CategoryAttribute CategoryAttribute Class

Definition

Attribute used to flag a class as a category that extends the API of another type.

[System.AttributeUsage(System.AttributeTargets.Class)]
public class CategoryAttribute : Attribute
type CategoryAttribute = class
    inherit Attribute
Inheritance
CategoryAttributeCategoryAttribute
Attributes

Remarks

This attribute is applied to static user code classes and will surface all of the exported methods and properties (those that have the ExportAttribute) to the provided system type.

This allows new methods to be introduced or implemented for all types in the class. For example, this can be used to provide a global implementation of some method across all of your types surfaced to Objective-C.

All managed extension methods must be static, but it's possible to create Objective-C instance methods using the standard syntax for extension methods in C#:


// Make "shouldAutoRotate" return true for all UIViewControllers in the application

[Category (typeof (UIViewController))] static class MyViewControllerMethods { [Export ("shouldAutorotate")] static bool ShouldAutoRotate (this UIViewController self) { return true; }

[Export ("supportedInterfaceOrientations")]
static UIInterfaceOrientationMask SupportedRotations (this UIViewController self) 
{
    return UIInterfaceOrientationMask.All;
}

}


// This example will add a native toUpper instance method to the NSString class, 
// which can be invoked from Objective-C.

[Category (typeof (NSString))] public static class MyStringCategory
{ [Export ("toUpper")] static string ToUpper (this NSString self) { return self.ToString ().ToUpper (); } }

Constructors

CategoryAttribute(Type) CategoryAttribute(Type)

The type that this category extends.

Properties

Name Name

The name of the category.

Type Type

The type that this category extends.

Applies to