Attributes Every .NET Developer Should Know About




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

AttributeUsageWhen 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 CompliantIndicates whether a program element is compliant with the Common Language Specification (CLS)
ConditionalIndicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined
DebuggableModifies code generation for runtime just-in-time (JIT) debugging
DebuggerDisplayDetermines how a class or field is displayed in the debugger variable windows
DebuggerStepThroughDebugger does not stop in a method marked with this attribute but does allow a breakpoint to be set in the method
DefaultValueSpecifies the default value for a property
DesignerSerializationVisibilitySpecifies the type of persistence to use when serializing a property on a component at design time
DescriptionSpecifies a description for a property or even
DisplayNameSpecifies the display name for a property, event, or public void method which takes no arguments
DllImportIndicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point
EditorBrowsableSpecifies that a property or method is viewable in an editor
FlagsIndicates that an enumeration can be treated as a bit field; that is, a set of flags
InternalsVisibleToSpecifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly
MTAThreadIndicates that the COM threading model for an application is multithreaded apartment (MTA)
NonSerializedIndicates that a field of a serializable class should not be serialized
ObsoleteMarks the program elements that are no longer in use
ParamArrayIndicates that a method will allow a variable number of arguments in its invocation
SerializableIndicates that a class can be serialized
WebMethodAdding this attribute to a method within an XML Web service created using ASP.NET makes the method callable from remote Web clients
WebServiceUsed to add additional information to an XML Web service, such as a string describing its functionalit
XMLIgnoreInstructs the Serialize method of the XmlSerializer not to serialize the public field or public read/write property value
XMLElementIndicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it
XMLRootControls XML serialization of the attribute target as an XML root element
XMLTextIndicates to the XmlSerializer that the member must be treated as XML text when the class that contains it is serialized or deserialized
ThreadStaticIndicates that the value of a static field is unique for each thread


Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Attributes Every .NET Developer Should Know About"
  1. osmirnov said...
    October 8, 2010 at 5:57 AM

    I couldn't agree more. But I'd add RuntimeCompatibility

 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions