Re: serializable
Peter Osucha <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Thank you Simon. That is indeed helpful information. -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Hewitt, Simon C. (Contractor) Sent: Friday, July 28, 2006 1:01 AM To: [email protected] Subject: Re: [DOTNET-CX] serializable Peter There are two completely different types of serialization. One is the simpler XmlSerializer you are using. This only looks at *public* properties/field etc. and, as you have found, uses XmlIgnoreAttribute amongst others. The second is the low-level serialization used by remoting etc via the BinaryFormatter and SoapFormatter. This will access private members via reflection or, for classes implementing Iserializable, let them define how it should be serialized. NonSerializableAttribute is recognized by this type of serialization. Rule of thumb: If you only interested in XmlSerializer then all its Attributes begin with "Xml". Ie XmlIgnore, XmlArray, XmlArrayItem etc. This is Ms-Help page for VS2003 that lists all these attributes: ms-help://MS.VSCC.2003/MS.MSDNQTR.2005OCT.1033/cpguide/html/cpconAttribu tesThatControlSerialization.htm Cheers Simon -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Peter Osucha Sent: 27 July 2006 15:50 To: [email protected] Subject: Re: [DOTNET-CX] serializable Hmmm, I achieved what I wanted by marking the property {get/set} with the [XmlIgnore] attribute instead of the [NonSerializable()] attribute. I guess I don't understand what the [NonSerializable()] attribute is for... Peter -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Peter Osucha Sent: Wednesday, July 26, 2006 4:49 PM To: [email protected] Subject: [DOTNET-CX] serializable I want to use one or two small xml files to persist some very basic applications settings and it seems that using xml files will probably be a better solution than my old way of using the registry. I am not well versed in XML. I spent a few hours looking through the Help system to learn more about reading and writing XML stuff - it seems that NET does a very solid job supporting such functionality. Anyway, when reviewing the XmlWriter and XmlReader classes, I stumbled on the 'serializable' attribute - which will make some of this persistence even easier. The problem I'm having is marking some things non-serializable and the Help system isn't helping me out here. In one main object I want to serialize, I have a field for an application password. The object has properties to return this password in an encrypted form and an unencrypted form - although there is only one private variable holding the password. So if I'm not mistaken, if I want to just mark the class serializable, then I need to create private variables for the encrypted password and the unencrypted password and mark the encrypted one as [NonSerializable()]. Is this correct? Is there a 'better' way (I haven't really looked at implementing ISerializable yet). Peter =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com