See Also: CategoryAttribute Members
This attribute is applied to static user code classes and will surface all of the exported methods and properties (those that have the Foundation.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#:
c# Example
// 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; } }
c# Example
// 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 (); } }