object. The XML generated is input to another system. This is just a one-way
a better solution. Would writing a new serializer be the only solution in
"Dino Chiesa [MSFT]" <dinoch@microsoft.com> wrote in message
news:%23tw4FSrVDHA.2012@TK2MSFTNGP10.phx.gbl...
> By default, no, you cannot serialize readonly properties to XML .
>
> But what do you really want to do? What's the end goal? There may be a
way
> to accomplish what you want.
>
> If you serialize with the BinaryFormatter, you can get all obj properties.
>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeSerializationFormattersBinaryBinaryFormatterClassTopic.asp >
> Alternatively, staying with the XmlSerializer, you could use a hack where
> you provide a public setter method, which does nothing. In this case the
> XML Serialization will work, but de-serialization may not behave the way
you
> want.
>
> public class MyClass {
> private int _myInt;
> public int MyInt {
> get { return _myInt; }
> set { } // do nothing!!
> }
> }
>
> But understand that in this case, at De-serialize time, your data will
> disappear. The XmlSerializer.Deserialize() method will call your setter,
> which will do nothing (by your design) and then the data from the XML file
> will NOT be set in the (deserialized) object instance.
>
> Also you will have confusing code that may be hard to use or hard to
> maintain later: Users of your class may invoke the setter expecting it to
> actually work.
>
>
> -Dino
>
>
>
> "Mudit" <muditv@grapecity.com> wrote in message
> news:e7MER9nVDHA.384@TK2MSFTNGP12.phx.gbl...
> > Hi,
> >
> > I am new to XML Serialization. I am interested in serializing my object
to
> > Xml. I only have to serialize and I needn't worry about deserialization.
> > As per my understanding, only the properties that have both "get" and
> "set"
> > can be serailized. Is that so. Is it also possible to serialize
properties
> > that are read only.
> >
> > Thanks,
> > Mudit
> >
> >
>
>