Kevin Spencer wrote:
Yes, ignore it. Take a cue from .NET serialization. It will only
serialize fields, it will not serialize properties (an indexer is a
property).
Actually, .Net *will* serialize properties, as long as they have a
get and a set accessor method.
Rubbish. Read up about serialization and learn how it works.
Apart from anything else, it makes no sense for properties to be
serialized. If you have a property that is based on a field then *two*
values will be serialized and that then raises the question of which
value will be used to 'initialize' the property. If the property is used
to calculate a value at runtime (for example, reads an item from a
database) then it will be dependent upon the actual time when the data
is read and serialization of such values makes no sense.
Just to prove that you are wrong, try this:
[Serializable]
public class DataItem
{
int data;
public int Data
{
get{return data;}
set{data=value;}
}
}
Then:
SoapFormatter sf = new SoapFormatter();
DataItem dataitem = new DataItem();
dataitem.Data = 42;
using (FileStream fs = File.OpenWrite("test.soap"))
{
sf.Serialize(fs, dataitem);
}
Run this code and view the file. You'll find an entry for DataItem.data,
and not for DataItem.Data:
<DataItem>
<data>42</data>
</DataItem>
Change DataItem to:
[Serializable]
public class DataItem
{
public int Data
{
get{return 42;}
set{Console::WriteLine("dont know what to do with {0}", value);}
}
}
Run the code again. You'll find no mention of Data.
You're wrong on this one, Kevin.
Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm http://www.grimes.demon.co.uk/workshops/securityWS.htm