Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / April 2006

Tip: Looking for answers? Try searching our database.

serialization in InitializeComponents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ivan - 12 Apr 2006 08:28 GMT
My custom composite control for the .NET Compact Framework will not serialize
the DesignTime DefaultValues I assign to properties.  For instance, VS
serializes '0' for ints and it serializes the first value for any enumeration
types.

For example:

// I implemented this default value via the “Custom Attributes
//  Form” or through DesignTimeAttributes.xmta rather.
[DefaultValue(2)]  
public int ButtonCount
{
   get{ return count;}
   set{ count = value;}
}

Considering the code snippet above you’d think the designer would serialize
the following…

Obj.ButtonCount = 2; // I would assume this serialization because
DefaultValue(2)

But instead I get…

Obj.ButtonCount = 0;

I can change the value of the property and the code reflects the change
correctly, but the designer doesn’t initially serialize the default value to
the property in InitializeComponents.  Consequently, when I change the
property value manually via the property grid to the default value, the
designer recognizes this and no longer serializes the property setting in
InitializeComponents.

Also, if I have:

Public enum PanelType
{
   NO_PANEL,
   BOTTOM_PANEL,
   TOP_PANEL
};

[DefaultValue(BOTTOM_PANEL)]
Public PanelType FormPanelType
{
   get{ return pType; }
   set{ pType = value;}
}

Here the same sort of issue arises … the designer only serializes NO_PANEL
initially, and disregards the DefaultValue.  Consequently, when the default
value is selected manually the default value isn’t recognized by the designer
and the default value setting is still serialized in InitializeComponents.  
This differs from the ‘int’ property above…

I’ve looked at many examples, and I am still unable to find the exact
configuration settings for this issue.

Any thoughts?

thanks
Tim Wilson - 12 Apr 2006 15:56 GMT
The DefaultValue attribute is simply metadata that is used at design-time to
decide if the value of a property needs to be serialized. In other words, if
the value has not changed from the default then the value should not be
serialized. You'll need to make sure that the actual value of the field
storing the property value is the same as the value specified in the
DefaultValue attribute.

private int count = 2;

[DefaultValue(2)]
public int ButtonCount
{
 get{ return count;}
 set{ count = value;}
}

Signature

Tim Wilson
.NET Compact Framework MVP

> My custom composite control for the .NET Compact Framework will not serialize
> the DesignTime DefaultValues I assign to properties.  For instance, VS
[quoted text clipped - 13 lines]
>
> Considering the code snippet above you'd think the designer would
serialize
> the following.
>
[quoted text clipped - 7 lines]
> I can change the value of the property and the code reflects the change
> correctly, but the designer doesn't initially serialize the default value
to
> the property in InitializeComponents.  Consequently, when I change the
> property value manually via the property grid to the default value, the
[quoted text clipped - 20 lines]
> initially, and disregards the DefaultValue.  Consequently, when the default
> value is selected manually the default value isn't recognized by the
designer
> and the default value setting is still serialized in InitializeComponents.
> This differs from the 'int' property above.
[quoted text clipped - 5 lines]
>
> thanks

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.