Search code examples
c#interfacedatacontractdatamember

What does it mean to put DataMemberAttribute on interface member?


What does it mean to put a DataMemberAttribute on an interface member? How does this affect derived classes?


Solution

  • As shown in the following signature, the DataMember attribute is not inheritable

    [AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false, 
        AllowMultiple = false)]
    public sealed class DataMemberAttribute : Attribute
    

    Therefore, it makes very little sense to decorate interface members with this attribute as you will have to decorate the implementing classes' members with this attribute too.