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 / May 2007

Tip: Looking for answers? Try searching our database.

How do you exclude a property from serialization using CodeDomSerializer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tribbles - 09 May 2007 00:07 GMT
You can use NonSerialized to exclude a field (not a property) from the
serializer.  If you are using the XmlSerializer you can use
XmlIgnore.  However, I can't find any way to exclude a property from
the CodeDomSerializer.  The problem I am trying to solve is that I
have Controls that have references to other controls.  I have used the
[NonSerialized] on several property to exclude the Control objects
from serialization and a bool property that indicates whether those
control references have been re-established after deserialization.

The control properties have a value of null that I want, but the bool
property has a value of true, when it should have a value of false.

So with a little debugging I noticed that without NonSerialized, the
serialization and deserialization would record and set public and
private fields in addition to public and private properties.  Field
were first, followed by properties.
Not having the NonSerialized set on the Control fields caused an
seriliazation exception as expected.  With, properites no exception
occurs, but no value is serialized.

So it appears to be by pure change that the Control properties are
working as I intended.  The boolean property on the other hand is
always serialized out, one way or the other. :(

All of these properties are part of an interface and you can not use
fields in interfaces, unless I'm missign something obvious and
wonderously useful...

So...  Any ideas on how to exclude properties from serialization,
besides coding my own serilization service and using the
XmlSerializer?  (Previous dev team attempted to use XmlSerializer and
said it didn't work, I have no real info on what didn't work though).

For additional context, serialization is used for cut/copy/paste/undo/
redo services.

       [NonSerialized]
       private bool controlsNormalized = false;
       public  bool ControlsNormalized {
           get { return controlsNormalized; }
           set { controlsNormalized = value; }
       }

       //
       // Don't serialize out, only used during design time.
       //
       [NonSerialized]
       private Control baseControl = null;
       public  Control BaseControl {
           get { return baseControl; }
           set { baseControl = value; }
       }
       //
       // This property is used with the auto Parser to serialize out
the control and to
       // deserialize the needed information to 'relink' to the
control in the designer.
       // Since there is no gaurantee that the control will have been
deserialized and added
       // to the designer before valdiation is deserialized, we need
a 2 step process.
       //
       private string baseControlName = "";
       public  string BaseControlName {
           get {
               if (BaseControl == null) {
                   return "";
               }

               return BaseControl.Name;
           }
           set { baseControlName = value; }
       }
Mick Doherty - 09 May 2007 09:53 GMT
Have you tried adding ShouldSerializePropertyName methods?

       private bool controlsNormalized = false;
       public bool ControlsNormalized
       {
           get { return controlsNormalized; }
           set { controlsNormalized = value; }
       }
       private bool ShouldSerializeControlsNormalized()
       { return false; }

       private Control baseControl = null;
       public Control BaseControl
       {
           get { return baseControl; }
           set { baseControl = value; }
       }
       private bool ShouldSerializeBaseControl()
       { return false; }

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

schneider - 09 May 2007 17:12 GMT
Also the attribute:

[DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden)]

> Have you tried adding ShouldSerializePropertyName methods?
>
[quoted text clipped - 15 lines]
>        private bool ShouldSerializeBaseControl()
>        { return false; }
tribbles - 09 May 2007 17:28 GMT
Wow!  I spent a day going over various documentation and did not see
anything about either method mentioned.  I tried the method and it
solved the problem nicely.  Thanks!
schneider - 10 May 2007 21:20 GMT
Yep, A lot of these little things come with experience building controls.

You might want to review the Attribute derived objects, there are a lot of
designer related items.

Schneider

> Wow!  I spent a day going over various documentation and did not see
> anything about either method mentioned.  I tried the method and it
> solved the problem nicely.  Thanks!
jokiz - 11 May 2007 11:44 GMT
or just read the designer related sample chapter of chris sell's book,
a lot stuff is in there
On May 11, 4:20 am, "schneider"
> Yep, A lot of these little things come with experience building controls.
>
[quoted text clipped - 6 lines]
> > anything about either method mentioned.  I tried the method and it
> > solved the problem nicely.  Thanks!
tribbles - 12 May 2007 00:22 GMT
> or just read the designer related sample chapter of chris sell's book,
> a lot stuff is in there

<snip>

Are you referring to this book: Windows Forms 2.0 Programming (2nd
Edition) ?

Always willing to buy a book that has good info in it.  Unfortunately
I have 4 books on windows forms that have nothing about designers in
them.  So any books with designer is of interest to me!
jokiz - 12 May 2007 03:20 GMT
yes, it has one chapter for design time integration.  i've also read a
book from bluevision but it's just a good reference but hard to
understand.

> > or just read the designer related sample chapter of chris sell's book,
> > a lot stuff is in there
[quoted text clipped - 7 lines]
> I have 4 books on windows forms that have nothing about designers in
> them.  So any books with designer is of interest to me!

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.