Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to NOT serialize a Property of a Class

Reply
Thread Tools

How to NOT serialize a Property of a Class

 
 
=?Utf-8?B?RWFybCBUZWlncm9i?=
Guest
Posts: n/a
 
      10-04-2004
I have a class that has some fields and properties that I want to serialize.
However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
and it will not serialize so I want to mark it as "NonSerialized". However,
this property is not allowed on a property of this type. How can I designate
this property so that I can serialize the rest of the call without
serializing this property???

Thanks!

Property myControl() As System.Web.UI.WebControls.WebControl
Get
Return _myControl
End Get
Set(ByVal Value As System.Web.UI.WebControls.WebControl)
_myControl = Value
End Set
End Property
 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      10-05-2004
Hi,

The first thing that comes to mind is using two separate methods for
getting/seting (eg: Get_myControl() and Set_myControl(Value As WebControl))
the field (_myControl) instead of the property (myControl()). Then just mark
the field _myControl with the NonSerializedAttribute.

Hope this helps
Martin
"Earl Teigrob" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a class that has some fields and properties that I want to

serialize.
> However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
> and it will not serialize so I want to mark it as "NonSerialized".

However,
> this property is not allowed on a property of this type. How can I

designate
> this property so that I can serialize the rest of the call without
> serializing this property???
>
> Thanks!
>
> Property myControl() As System.Web.UI.WebControls.WebControl
> Get
> Return _myControl
> End Get
> Set(ByVal Value As System.Web.UI.WebControls.WebControl)
> _myControl = Value
> End Set
> End Property



 
Reply With Quote
 
 
 
 
BluDog
Guest
Posts: n/a
 
      10-05-2004
<System.Xml.Serialization.XmlIgnore()> _
Property myControl() As System.Web.UI.WebControls.WebControl
Get
Return _myControl
End Get
Set(ByVal Value As System.Web.UI.WebControls.WebControl)
_myControl = Value
End Set
End Property


Hope this helps

Blu.
 
Reply With Quote
 
=?Utf-8?B?RWFybCBUZWlncm9i?=
Guest
Posts: n/a
 
      10-05-2004
Thank you Both ForYour answers. I used the combination of your answers to
solve my issue and it works great! Here is what my class ends up looking like


<Serializable()> _
Class TabMenuItem
....
<NonSerialized()> Private _RenderControl As
System.Web.UI.WebControls.WebControl

....

<System.Xml.Serialization.XmlIgnore()> _
Property RenderControl() As System.Web.UI.WebControls.WebControl
Get
If Not _RenderControl Is Nothing Then
Return _RenderControl
Else
_RenderControl =
System.Activator.CreateInstance(ControlType)
_RenderControl.ID = ControlId
Return _RenderControl
End If
End Get
Set(ByVal Value As System.Web.UI.WebControls.WebControl)
_RenderControl = Value
ControlType = Value.GetType
ControlId = Value.ID
End Set
End Property
....

End Class

"Earl Teigrob" wrote:

> I have a class that has some fields and properties that I want to serialize.
> However, one of the fields is of type System.Web.UI.Webcontrols.Webcontrol
> and it will not serialize so I want to mark it as "NonSerialized". However,
> this property is not allowed on a property of this type. How can I designate
> this property so that I can serialize the rest of the call without
> serializing this property???
>
> Thanks!
>
> Property myControl() As System.Web.UI.WebControls.WebControl
> Get
> Return _myControl
> End Get
> Set(ByVal Value As System.Web.UI.WebControls.WebControl)
> _myControl = Value
> End Set
> End Property

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OO Javascript - Class.Prototype.Property vs. This.Property Spam Catcher Javascript 4 11-21-2007 05:23 PM
Serialize a class (not an object) cyberco Java 5 05-05-2006 04:32 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
How to serialize an extended property for a Webcontrol? Stefaan V. ASP .Net Building Controls 0 10-07-2004 07:51 AM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM



Advertisments