4
[DataContract]
public class SearchResults
{
    [DataMember]
    public List<SearchDetail> PList { get; set; }
    [DataMemberAttribute]
    public int Count { get; set; }
}

The metadata for DataMember and DataMemberAttribute are same.

Is 'DataMember' just an alias of the other? Which one should we be using? (If possible please provide a link)

VoodooChild
  • 9,776
  • 8
  • 66
  • 99

3 Answers3

4

By convention, all attribute names end with Attribute. However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize System.ObsoleteAttribute, you only need to reference it as Obsolete.

Source - https://learn.microsoft.com/en-us/dotnet/standard/attributes/applying-attributes

It is same and for all the attribute in .Net Framework it is applicable. Ex. Serializable

Pang
  • 9,564
  • 146
  • 81
  • 122
Anuraj
  • 18,859
  • 7
  • 53
  • 79
  • 1
    The convention is to name the class with the "Attribute" appended, but in usage to omit it. – rkaregaran May 18 '11 at 05:07
  • @rkaregaran: could you provide an official link to your comment statement. I tried google but it's no help (or maybe it late :P). Thanks! – VoodooChild May 18 '11 at 05:09
3

Yes, the 'Attribute' on the attribute name is optional. Use whatever makes you happy.

Attributes on MSDN (See the Note 2/3rd's down)

Note

By convention, all attribute names end with the word "Attribute" to distinguish them from other items in the .NET Framework. However, you do not need to specify the attribute suffix when using attributes in code. For example, [DllImport] is equivalent to [DllImportAttribute], but DllImportAttribute is the attribute's actual name in the .NET Framework.

Pang
  • 9,564
  • 146
  • 81
  • 122
Ritch Melton
  • 11,498
  • 4
  • 41
  • 54
1

You can use any attribute with the ending -Attribute in .NET, i.e. to use the full name of the attribute type. Just to keep it simple, the ending is allowed to be omitted.

Centro
  • 3,892
  • 2
  • 25
  • 31