Change Property from a base class to [NonSerialized]
So I have a base class and there a property that is set to be [Serializable]. In the derived class I would like to make that property [N开发者_运维问答onSerialized].
How can this be done?
This would be a violation of OOP. The base class has established the fact that this property is serializable. It must be possible to substitute any instance of a derived class for an instance of the base class. This means that every instance of the derived class must have that property serializable.
You cannot substitute a new attribute, but you can define a property called ShouldSerializePropertyName
(where PropertyName
is the name of your property) that always returns false
. This should override the presence of the attribute on the property.
For example,
public class BaseClass
{
[Serialized]
public string MyProperty { get; set; }
}
public class ChildClass : BaseClass
{
public bool ShouldSerializeMyProperty { get { return false; } }
}
精彩评论