# AttributeUsageAttribute

***

**1. Attribute Usage for Class**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomClassAttribute : Attribute
{
    // Attribute properties
}

[CustomClassAttribute]
public class MyClass
{
    // Class implementation
}
```

**2. Attribute Usage for Method**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class CustomMethodAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomMethodAttribute]
    public void MyMethod()
    {
        // Method implementation
    }
}
```

**3. Attribute Usage for Property**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomPropertyAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomPropertyAttribute]
    public string MyProperty { get; set; }
}
```

**4. Attribute Usage for Field**

```csharp
[AttributeUsage(AttributeTargets.Field)]
public class CustomFieldAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomFieldAttribute]
    public int MyField;
}
```

**5. Attribute Usage for Parameter**

```csharp
[AttributeUsage(AttributeTargets.Parameter)]
public class CustomParameterAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public void MyMethod([CustomParameterAttribute] int myParameter)
    {
        // Method implementation
    }
}
```

**6. Attribute Usage for Return Value**

```csharp
[AttributeUsage(AttributeTargets.ReturnValue)]
public class CustomReturnValueAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public [CustomReturnValueAttribute] int MyMethod()
    {
        // Method implementation
        return 10;
    }
}
```

**7. Attribute Usage for Assembly**

```csharp
[AttributeUsage(AttributeTargets.Assembly)]
public class CustomAssemblyAttribute : Attribute
{
    // Attribute properties
}

[CustomAssemblyAttribute]
public class MyAssembly
{
    // Assembly implementation
}
```

**8. Attribute Usage for Module**

```csharp
[AttributeUsage(AttributeTargets.Module)]
public class CustomModuleAttribute : Attribute
{
    // Attribute properties
}

[CustomModuleAttribute]
public class MyModule
{
    // Module implementation
}
```

**9. Attribute Usage for Constructor**

```csharp
[AttributeUsage(AttributeTargets.Constructor)]
public class CustomConstructorAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomConstructorAttribute]
    public MyClass()
    {
        // Constructor implementation
    }
}
```

**10. Attribute Usage for Enum**

```csharp
[AttributeUsage(AttributeTargets.Enum)]
public class CustomEnumAttribute : Attribute
{
    // Attribute properties
}

[CustomEnumAttribute]
public enum MyEnum
{
    Value1,
    Value2
}
```

**11. Attribute Usage for Enum Member**

```csharp
[AttributeUsage(AttributeTargets.EnumMember)]
public class CustomEnumMemberAttribute : Attribute
{
    // Attribute properties
}

public enum MyEnum
{
    [CustomEnumMemberAttribute]
    Value1,
    Value2
}
```

**12. Attribute Usage for Interface**

```csharp
[AttributeUsage(AttributeTargets.Interface)]
public class CustomInterfaceAttribute : Attribute
{
    // Attribute properties
}

[CustomInterfaceAttribute]
public interface IMyInterface
{
    // Interface implementation
}
```

**13. Attribute Usage for Delegate**

```csharp
[AttributeUsage(AttributeTargets.Delegate)]
public class CustomDelegateAttribute : Attribute
{
    // Attribute properties
}

[CustomDelegateAttribute]
public delegate void MyDelegate();
```

**14. Attribute Usage for Event**

```csharp
[AttributeUsage(AttributeTargets.Event)]
public class CustomEventAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomEventAttribute]
    public event EventHandler MyEvent;
}
```

**15. Attribute Usage for Type Parameter**

```csharp
[AttributeUsage(AttributeTargets.GenericParameter)]
public class CustomTypeParameterAttribute : Attribute
{
    // Attribute properties
}

public class MyClass<T> where T : IComparable<T>
{
    [CustomTypeParameterAttribute]
    public T MyProperty { get; set; }
}
```

**16. Attribute Usage for Method Parameter**

```csharp
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
public class CustomParameterAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public void MyMethod([CustomParameterAttribute(1)] int myParameter1, [CustomParameterAttribute(2)] int myParameter2)
    {
        // Method implementation
    }
}
```

**17. Attribute Usage for Property Parameter**

```csharp
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class CustomPropertyAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public string MyProperty { [CustomPropertyAttribute(1)] get; [CustomPropertyAttribute(2)] set; }
}
```

**18. Attribute Usage for Field Parameter**

```csharp
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class CustomFieldAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public int MyField1;

    [CustomFieldAttribute(1)]
    public int MyField2;

    [CustomFieldAttribute(2)]
    public int MyField3;
}
```

**19. Attribute Usage for Interface Method**

```csharp
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
public class CustomInterfaceMethodAttribute : Attribute
{
    // Attribute properties
}

public interface IMyInterface
{
    [CustomInterfaceMethodAttribute]
    void MyMethod();
}
```

**20. Attribute Usage for Property Indexer**

```csharp
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class CustomPropertyIndexerAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public int this[[CustomPropertyIndexerAttribute(1)] int index] { get; set; }

    public int this[[CustomPropertyIndexerAttribute(2)] string index] { get; set; }
}
```

**21. Attribute Usage for Enum Field**

```csharp
[AttributeUsage(AttributeTargets.Field)]
public class CustomEnumFieldAttribute : Attribute
{
    // Attribute properties
}

public enum MyEnum
{
    [CustomEnumFieldAttribute(1)]
    Value1,

    [CustomEnumFieldAttribute(2)]
    Value2
}
```

**22. Attribute Usage for Interface Property**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomInterfacePropertyAttribute : Attribute
{
    // Attribute properties
}

public interface IMyInterface
{
    [CustomInterfacePropertyAttribute]
    int MyProperty { get; set; }
}
```

**23. Attribute Usage for Delegate Method**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class CustomDelegateMethodAttribute : Attribute
{
    // Attribute properties
}

public delegate void MyDelegate();

public class MyClass
{
    [CustomDelegateMethodAttribute]
    public static void MyMethod()
    {
        // Method implementation
    }
}
```

**24. Attribute Usage for Event Handler**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class CustomEventHandlerAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public event EventHandler MyEvent;

    [CustomEventHandlerAttribute]
    public void MyEventHandler(object sender, EventArgs e)
    {
        // Event handler implementation
    }
}
```

**25. Attribute Usage for Generic Type Parameter Constraint**

```csharp
[AttributeUsage(AttributeTargets.GenericParameter)]
public class CustomGenericTypeParameterConstraintAttribute : Attribute
{
    // Attribute properties
}

public class MyClass<T> where T : IComparable<T>
{
    [CustomGenericTypeParameterConstraintAttribute]
    public T MyProperty { get; set; }
}
```

**26. Attribute Usage for Ref Parameter**

```csharp
[AttributeUsage(AttributeTargets.Parameter, Inherited = true)]
public class CustomRefParameterAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public void MyMethod([CustomRefParameterAttribute] ref int myParameter)
    {
        // Method implementation
    }
}
```

**27. Attribute Usage for Out Parameter**

```csharp
[AttributeUsage(AttributeTargets.Parameter, Inherited = true)]
public class CustomOutParameterAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    public void MyMethod([CustomOutParameterAttribute] out int myParameter)
    {
        myParameter = 10;
    }
}
```

**28. Attribute Usage for TypeConverter**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomTypeConverterAttribute : Attribute
{
    // Attribute properties
}

[CustomTypeConverterAttribute(typeof(MyTypeConverter))]
public class MyType
{
    // Type implementation
}

public class MyTypeConverter : TypeConverter
{
    // Type converter implementation
}
```

**29. Attribute Usage for DesignerSerializationVisibility**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomDesignerSerializationVisibilityAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomDesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
    public int MyProperty { get; set; }
}
```

**30. Attribute Usage for Obsolete**

```csharp
[AttributeUsage(AttributeTargets.All, Inherited = true)]
public class CustomObsoleteAttribute : Attribute
{
    // Attribute properties
}

[CustomObsoleteAttribute("Use MyNewMethod instead.")]
public void MyOldMethod()
{
    // Method implementation
}

public void MyNewMethod()
{
    // Method implementation
}
```

**31. Attribute Usage for CompilationRelaxations**

```csharp
[AttributeUsage(AttributeTargets.Assembly)]
public class CustomCompilationRelaxationsAttribute : Attribute
{
    // Attribute properties
}

[CustomCompilationRelaxationsAttribute(CompilationRelaxations.NoStringInterning)]
public class MyAssembly
{
    // Assembly implementation
}
```

**32. Attribute Usage for SuppressMessage**

```csharp
[AttributeUsage(AttributeTargets.All, Inherited = true)]
public class CustomSuppressMessageAttribute : Attribute
{
    // Attribute properties
}

[CustomSuppressMessageAttribute("Microsoft.Design", "CA1050:DeclareAggregatesAsArrays")]
public class MyClass
{
    // Class implementation
}
```

**33. Attribute Usage for DefaultMember**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomDefaultMemberAttribute : Attribute
{
    // Attribute properties
}

[CustomDefaultMemberAttribute("MyProperty")]
public class MyClass
{
    public int MyProperty { get; set; }
}
```

**34. Attribute Usage for Serializable**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomSerializableAttribute : Attribute
{
    // Attribute properties
}

[CustomSerializableAttribute]
public class MyClass : ISerializable
{
    // Serialization implementation
}
```

**35. Attribute Usage for XmlRoot**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomXmlRootAttribute : Attribute
{
    // Attribute properties
}

[CustomXmlRootAttribute("MyRootElement")]
public class MyClass
{
    // XML serialization implementation
}
```

**36. Attribute Usage for XmlElement**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomXmlElementAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomXmlElementAttribute("MyElement")]
    public int MyProperty { get; set; }
}
```

**37. Attribute Usage for XmlAttribute**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomXmlAttributeAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomXmlAttributeAttribute("MyAttribute")]
    public string MyProperty { get; set; }
}
```

**38. Attribute Usage for XmlIgnore**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomXmlIgnoreAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomXmlIgnoreAttribute]
    public int MyProperty { get; set; }
}
```

**39. Attribute Usage for XmlEnum**

```csharp
[AttributeUsage(AttributeTargets.Enum)]
public class CustomXmlEnumAttribute : Attribute
{
    // Attribute properties
}

[CustomXmlEnumAttribute("MyEnum")]
public enum MyEnum
{
    Value1,
    Value2
}
```

**40. Attribute Usage for XmlMember**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomXmlMemberAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomXmlMemberAttribute]
    public int MyProperty { get; set; }
}
```

**41. Attribute Usage for SoapHeader**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomSoapHeaderAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomSoapHeaderAttribute("MyHeader")]
    public string MyProperty { get; set; }
}
```

**42. Attribute Usage for SoapMessageBody**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class CustomSoapMessageBodyAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomSoapMessageBodyAttribute("MyBody")]
    public void MyMethod()
    {
        // Method implementation
    }
}
```

**43. Attribute Usage for SoapOperation**

```csharp
[AttributeUsage(AttributeTargets.Method)]
public class CustomSoapOperationAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomSoapOperationAttribute("MyOperation")]
    public void MyMethod()
    {
        // Method implementation
    }
}
```

**44. Attribute Usage for AspSessionState**

```csharp
[AttributeUsage(AttributeTargets.Class)]
public class CustomAspSessionStateAttribute : Attribute
{
    // Attribute properties
}

[CustomAspSessionStateAttribute(SessionStateBehavior.ReadOnly)]
public class MyClass : IHttpHandler
{
    // HTTP handler implementation
}
```

**45. Attribute Usage for NavigationPageProperty**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPagePropertyAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPagePropertyAttribute]
    public string MyProperty { get; set; }
}
```

**46. Attribute Usage for NavigationPageText**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPageTextAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPageTextAttribute]
    public string MyProperty { get; set; }
}
```

**47. Attribute Usage for NavigationPageImage**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPageImageAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPageImageAttribute]
    public string MyProperty { get; set; }
}
```

**48. Attribute Usage for NavigationPageIcon**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPageIconAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPageIconAttribute]
    public string MyProperty { get; set; }
}
```

**49. Attribute Usage for NavigationPageUrl**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPageUrlAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPageUrlAttribute]
    public string MyProperty { get; set; }
}
```

**50. Attribute Usage for NavigationPageTile**

```csharp
[AttributeUsage(AttributeTargets.Property)]
public class CustomNavigationPageTileAttribute : Attribute
{
    // Attribute properties
}

public class MyClass
{
    [CustomNavigationPageTileAttribute]
    public string MyProperty { get; set; }
}
```
