A .NET attribute is an object, that provides a mechanism to associate information (metadata) with an element in your program. The Common Language Runtime (CLR) then uses these attributes and determines how to interact with these elements. You can also create custom attributes and use reflection to read them later.
Here’s a list of important .NET attributes that is commonly used in projects and proves very useful if you know about them beforehand. This list is just a compilation (arranged alphabetically) and clicking on each attribute will take you to a msdn link which explains its usage with an example. If you are unclear about the usage of any of the attributes listed here, drop me a comment and I will explain it.
.NET Attribute | Description |
AttributeUsage | When you are defining your own attribute class, you can control the manner in which it is used by placing an AttributeUsageAttribute on your attribute class |
CLS Compliant | Indicates whether a program element is compliant with the Common Language Specification (CLS) |
Conditional | Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined |
Debuggable | Modifies code generation for runtime just-in-time (JIT) debugging |
DebuggerDisplay | Determines how a class or field is displayed in the debugger variable windows |
DebuggerStepThrough | Debugger does not stop in a method marked with this attribute but does allow a breakpoint to be set in the method |
DefaultValue | Specifies the default value for a property |
DesignerSerializationVisibility | Specifies the type of persistence to use when serializing a property on a component at design time |
Description | Specifies a description for a property or even |
DisplayName | Specifies the display name for a property, event, or public void method which takes no arguments |
DllImport | Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point |
EditorBrowsable | Specifies that a property or method is viewable in an editor |
Flags | Indicates that an enumeration can be treated as a bit field; that is, a set of flags |
InternalsVisibleTo | Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly |
MTAThread | Indicates that the COM threading model for an application is multithreaded apartment (MTA) |
NonSerialized | Indicates that a field of a serializable class should not be serialized |
Obsolete | Marks the program elements that are no longer in use |
ParamArray | Indicates that a method will allow a variable number of arguments in its invocation |
Serializable | Indicates that a class can be serialized |
WebMethod | Adding this attribute to a method within an XML Web service created using ASP.NET makes the method callable from remote Web clients |
WebService | Used to add additional information to an XML Web service, such as a string describing its functionalit |
XMLIgnore | Instructs the Serialize method of the XmlSerializer not to serialize the public field or public read/write property value |
XMLElement | Indicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it |
XMLRoot | Controls XML serialization of the attribute target as an XML root element |
XMLText | Indicates to the XmlSerializer that the member must be treated as XML text when the class that contains it is serialized or deserialized |
ThreadStatic | Indicates that the value of a static field is unique for each thread |
Tweet
No comments:
Post a Comment