Jeroen said:
[...]
And that note should also include write-only properties, but it doesn't,
because write-only properties are a bad idea to begin with. See
http://msdn.microsoft.com/library/ms182165.
I would not go so far as the code analysis rule given. Just as one
common use for read-only properties are when they are synthetic and it
doesn't make sense to write the value, so too can it sometimes make
sense to have a synthetic write-only property, where it doesn't make
sense to read the value (because it's setting some state that doesn't
actually correspond to one single thing, or even some stable combination
of things).
I would certainly agree that it's something to use carefully and only
when it clearly makes sense. The situations when a write-only property
is good design are very rare.
In the class being shown here, I think the read-only _and_ write-only
property is just plain absurd. The whole point of a property is to have
a single class member that encapsulates a value, and when that value can
be both read and written, to split that value between two different
properties seems ridiculous to me.
I suspect that the OP will have much more success with the serialization
if the class is changed so that it just looks like this:
[Serializable]
public class Result
{
private string data;
public Result()
{
}
public Result(string data)
{
this.data = data;
}
public string Data
{
get{return data;}
set{data=value;}
}
}
Of course, there still remains the question why the OP has a whole class
just to wrap a string value. Why doesn't he just serialize the string
value instead of messing around with the class?
But having a simple read/write property should make serialization go a
lot better, I would think.
Pete
.