DataMember vs DataMemberAttribute

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

The metadata for DataMember and DataMemberAttribute same.

Is "DataMember" just an alias of another? Which one should we use? (If possible, provide a link)

+4
source share
3 answers

Yes, the β€œAttribute” in the attribute name is optional. Use what makes you happy.

Attributes on MSDN (see note 2/3 down)

+3
source

UPDATE: By convention, all attribute names end with an attribute. However, several runtime-oriented languages, such as Visual Basic and C #, do not require a fully qualified attribute name. For example, if you want to initialize System.ObsoleteAttribute, you only need to refer to it as deprecated.

Source - http://msdn.microsoft.com/en-us/library/bfz783fz.aspx

This is the same for all attributes in the .Net Framework, it applies. Ex. Serializable

+4
source

You can use any attribute ending with -Attribute in .NET, i.e. use the fully qualified attribute type name. Just to make it simple, the finale can be omitted.

+1
source

All Articles