I need to make a class Serializable. In this class I have a MyGuid readonly property, that I want to be serializable but not deserializable (property is initialized in a backing field). Using base serialization .NET features, you know, have a reandonly property make deserialization fail, 'cause it cannot deserialize a readonly property. So I decide to create a public get-set MyGuid property with a backing field, and make setter do nothing:
[Serializable]
public class Task : ITask
{
private readonly Guid m_guid = Guid.NewGuid();
public MyGuid Guid
{
get { return m_guid; }
set { /*Empty setter!*/ }
}
}
Now I don't want to shoot in my foot... There's a way I can make setter of MyGuid property as "deprecable" or "disabled"? It would be nice have Visual Studio warning me if I try to use the setter.
Or, instead, there's a better way to manage this kind of needs?
Thank you!
Edit: Found something here: Serializing private member data I'm reading...