NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

System.AttributeUsageAttribute

[AttributeUsageAttribute (AttributeTargets.Attribute)]
public sealed class AttributeUsageAttribute : Attribute
{
   public AttributeUsageAttribute (AttributeTargets validOn);
public AttributeUsageAttribute (AttributeTargets validOn, bool inherited, bool allowMultiple); //Obsolete
public bool AllowMultiple { virtual get; virtual set;}
public bool Inherited { virtual get; virtual set; }
public AttributeTargets ValidOn { virtual get; }
}

This attribute allows some customization of how the attribute it is attached to is treated.

ValidOn

This property indicates on which elements the attribute may be attached. It is legal to OR multiple targets together to get the right combination. For example the following would indicate that the attribute is allowed to be applied to any Type or any Methods.

[AttributeUsage (AttributeTargets.Type | AttributeTargets.Method)];
public class FooAttribute : Attribute
{
}

If this attribute were applied to Property, the compiler would give an error.

[FooAttribute]  //OK
public class CheckingAccount 
{
   [FooAttribute] //OK
   public void TransferFunds (String name) {…};

   [FooAttribute] //Error! Balance is a property
   public Decimal Balance {get {…}};
}

See System. AttributeTargets for more information.
The default is AttributeTargets.All.

Inherited

This property indicates if the attribute is to be inherited by subclasses or not. Compilers provide no special support for this functionality; it is the job of the attribute consumers (Reflection, etc) to respect this information. If allowMultiple is true, the attributes accumulate on the derived member; if allowMultiple is false, these attributes will override (or replace) in inheritance.

For example the BarAttribute is inherited but the BazAttribute is not.

//Defaults to Inherited=true
public class BarAttribute : Attribute
{
}

[AttributeUsageAttribute (Inherited = false)]; 
public class BazAttribute : Attribute
{
}

The BarAttribute is inherited but the BazAttribute is not.

public class Account 
{
   public void TransferFunds (String name) {…};

   [BarAttribute]
   [BazAttribute]
   public Decimal Balance {get {…}};
}

public class CheckingAccount : Account
{
    //Reflection will show Balance as having the BarAttribute 
//but not the BazAttribute.
    public Decimal Balance {get {…}};
}

Notice, only Attributes on Types, Methods, Properties, Events, Parameters are inherited.

See Reflection Support for more information.
The default is Inherited = true.

AllowMultiple

This property indicates if more than one instance of the attribute is allowed to exist on the same element. In heritance, if this value is true, the attributes accumulate on the derived member; if the value is false, these attributes will override (or replace) in inheritance.

//Defaults to AllowMultiple=false
public class BarAttribute : Attribute
{
}

[AttributeUsageAttribute (AllowMultiple = true)]; 
public class AuthorAttribute : Attribute
{
    public AuthorAttribute (String name) {…};
}

The BarAttribute is not allowed to be duplicated but the BazAttribute is.

public class Account 
{
   [BarAttribute]
   [BarAttribute] //Error: duplicates are not allowed.
   public void TransferFunds (String name) {…};

   [AuthorAttribute (“Bob Jones”)]
   [AuthorAttribute (“Mary Jane”)] 
   public Decimal Balance {get {…}};
}

See Reflection Support for more information.
The default is AllowMultiple = false.