I have a base class with DataMember properties in it. I also have a derived class with DataMember properties in it. In my WCF project I am returning the derived class. Is there a way for me to prevent a member in my base class from serializing? Here is some sample code:
public class BaseClass
{
public string ShortDescription {get;set;}
public string LongDescription {get;set;}
}
public class DerivedClass : BaseClass
{
public List<Description> Descriptions {get;set;}
}
In this code I want to be able to hide the inherited members ShortDescription and LongDescription because they are now obsolete. Any attempts to do so have been unsuccessful. Here is what I have tried:
public class DerivedClass : BaseClass
{
[DataMember]
public List<Description> Descriptions {get;set;}
// override the base class members
[IgnoreDataMember]
public override string ShortDescription {get;set;}
[IgnoreDataMember]
public override string LongDescription {get;set;}
}
and
public class DerivedClass : BaseClass
{
[DataMember]
public List<Description> Descriptions {get;set;}
// shadow the base class members
[IgnoreDataMember]
public new string ShortDescription {get;set;}
[IgnoreDataMember]
public new string LongDescription {get;set;}
}
Neither of these approaches have worked. The "DerivedClass" type when output to the WSDL still contains the "Ignored" members of the base class type.
You may wonder why I'm not just changing the base class. This is because I still use the base class in its original form as the previous version of the type for the WSDL to support backwards compatibility for consumers. In this way I can have a v1000 call that returns BaseClass and a V1010 call that returns a DerivedClass. I can add and change functionality to the DerivedClass all I want without the potential for affecting consumers of the v1000 functionality.