Basically, should the code below work and serialize string Yoyo when an object of type YoyoData is returned over the wire.
public interface IHelloV1
{
#region Instance Properties
[DataMember(Name = "Yoyo")]
string Yoyo { get; set; }
#endregion
}
[DataContract(Name = "YoyoData", Namespace = "http://hello.com/1/IHelloV1")]
public class YoyoData : IHelloV1
{
string Yoyo { get; set; }
public YoyoData()
{
Yoyo = "whatever";
}
}
}
I don’t think it will.
The
DataMemberattribute is not inherited in derived classes.For more details see documentation of type
DataMemberAttributeand how it is defined : http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx.This attribute specifies the property
Inherited = falsemeaning the attribute won’t be propagated to derived classes.Also see http://msdn.microsoft.com/en-us/library/84c42s56(v=vs.71).aspx for more details concerning the
Inheritedproperty on attributes.Anyway, this means that in your class defining the
DataContract, the propertyYoyowon’t be considered aDataMemberso for me it will just not work as expected.