Professional Documents
Culture Documents
System.NonSerializedAttribute [NonSerialized]
Allows certain members to be nonserialized so that data
won’t be saved to disk or over a network. Similar to the
transient keyword in Java.
System.Web.Services.WebServiceAttribute
Allows you to specify a name [WebService] and
description for a Web service.
System.Web.Services.WebMethodAttribute
Marks a method to be [WebMethod] exposed as part of a
Web service.
System.AttributeUsageAttribute
Defines the usage parameters [AttributeUsage] for
custom attributes.
System.ObsoleteAttribute [Obsolete]
Marks a specific section of code as obsolete.
Example
using System;
[Serializable]// OR [Serializable, WebService]
class SerialaizableClass
{
//Class definition here
}
using System;
[AttributeUsage(AttributeTargets.Assembly
| AttributeTargets.Class
| AttributeTargets.Method,
AllowMultiple=true)]
public class AAAttribute : System.Attribute{
…}
Accessing Attributes Through
Reflection
class MainClass {
public static void Main()
{ System.Reflection.MemberInfo info =
typeof(MyClass);
object[] attributes = info.GetCustomAttributes(true);
for (int i = 0; i < attributes.Length; i ++)
{
System.Console.WriteLine(attributes[i]);
} Specifies to search the attribute in
} } inheritance heirarchy.