c# - Using XmlIgnoreAttribute to Ignore Base Class Property -


i have abstract base class have added virtual properties. to, in derived class, specify particular base class property ignored during serialization(and deserialization process). see below, value-property in baseclass-class declared virtual property, , in derivedclass-class, using overrides-keyword, have chosen override base class's ppty , put xmlignoreattribute-attribute on it. however, when test code, still find value ppty included in generated xml derived class instance. same thing happens definition ppty, rendered though hide in derived class using new keyword, , apply xmlignoreattribute well. wrong code below please?

public abstract class baseclass {     public virtual string value { get; set; }       public string definition { get; set; }      [xmlattribute("separatorcharacter")]     public virtual string separatorcharacter { get; set; } }   public class derivedclass:baseclass {     [xmlignore()]     public overrides string value { get; set; }      [xmlattribute("fillercharacter")]     public string fillvalue { get; set; }       [xmlignore()]     public new string definition { get; set; } } 

the serializer not consider attribute on override property, whether supply attribute or through xmlattributeoverrides. partial workaround obtain behavior want add virtual shouldserializevalue method base class , override in derived class suppress serialization of value. won't prevent deserialization of value, can make override setter empty.

public abstract class baseclass {     public virtual string foo { get; set; }     public virtual bool shouldserializefoo () { return true ; } }  public class derivedclass:baseclass {     public override string foo { get; set; }     public override bool shouldserializefoo () { return false ; } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -