|
1 | 1 | // |
2 | | -// CategoryAttribyute.cs: |
| 2 | +// CategoryAttribute.cs: |
3 | 3 | // |
4 | 4 | // Authors: |
5 | 5 | // Rolf Bjarne Kvinge <rolf@xamarin.com> |
6 | 6 | // |
7 | 7 | // Copyright 2015 Xamarin Inc. |
8 | 8 |
|
9 | | -// Disable until we get around to enable + fix any issues. |
10 | | -#nullable disable |
| 9 | +#nullable enable |
11 | 10 |
|
12 | 11 | namespace ObjCRuntime { |
13 | | - /// <include file="../../docs/api/ObjCRuntime/CategoryAttribute.xml" path="/Documentation/Docs[@DocId='T:ObjCRuntime.CategoryAttribute']/*" /> |
| 12 | + /// <summary>Attribute used to flag a class as a category that extends another type.</summary> |
| 13 | + /// <remarks> |
| 14 | + /// <para>This attribute is applied to static user-code classes and surfaces all exported methods and properties (those with the <see cref="Foundation.ExportAttribute"/>) to the provided system type.</para> |
| 15 | + /// <para>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 your types surfaced to Objective-C.</para> |
| 16 | + /// <para>All managed extension methods must be static, but it is possible to create Objective-C instance methods using the standard syntax for extension methods in C#:</para> |
| 17 | + /// <example> |
| 18 | + /// <code lang="csharp"><![CDATA[ |
| 19 | + /// // Make "shouldAutoRotate" return true for all UIViewControllers in the application |
| 20 | + /// |
| 21 | + /// [Category (typeof (UIViewController))] |
| 22 | + /// static class MyViewControllerMethods { |
| 23 | + /// [Export ("shouldAutorotate")] |
| 24 | + /// static bool ShouldAutoRotate (this UIViewController self) |
| 25 | + /// { |
| 26 | + /// return true; |
| 27 | + /// } |
| 28 | + /// |
| 29 | + /// [Export ("supportedInterfaceOrientations")] |
| 30 | + /// static UIInterfaceOrientationMask SupportedRotations (this UIViewController self) |
| 31 | + /// { |
| 32 | + /// return UIInterfaceOrientationMask.All; |
| 33 | + /// } |
| 34 | + /// } |
| 35 | + /// ]]></code> |
| 36 | + /// </example> |
| 37 | + /// <example> |
| 38 | + /// <code lang="csharp"><![CDATA[ |
| 39 | + /// // This example adds a native toUpper instance method to the NSString class, |
| 40 | + /// // which can be invoked from Objective-C. |
| 41 | + /// |
| 42 | + /// [Category (typeof (NSString))] |
| 43 | + /// public static class MyStringCategory |
| 44 | + /// { |
| 45 | + /// [Export ("toUpper")] |
| 46 | + /// static string ToUpper (this NSString self) |
| 47 | + /// { |
| 48 | + /// return self.ToString ().ToUpper (); |
| 49 | + /// } |
| 50 | + /// } |
| 51 | + /// ]]></code> |
| 52 | + /// </example> |
| 53 | + /// <para>If the managed class is not referenced by other managed code (and is only called from Objective-C), the managed linker may remove it. This can be avoided by either adding a <see cref="Foundation.PreserveAttribute"/> attribute to the class, or by creating a custom linker definition file.</para> |
| 54 | + /// <para>See <see href="https://docs.microsoft.com/xamarin/cross-platform/deploy-test/linker">Custom Linker Configuration</see> for more information.</para> |
| 55 | + /// </remarks> |
14 | 56 | [AttributeUsage (AttributeTargets.Class)] |
15 | 57 | public class CategoryAttribute : Attribute { |
16 | | - /// <param name="type">The Objective-C type to extend. This must be a subclass of NSObject (or NSObject itself).</param> |
17 | | - /// <summary>The type that this category extends.</summary> |
18 | | - /// <remarks> |
19 | | - /// </remarks> |
| 58 | + /// <summary>Initializes a new instance of the <see cref="CategoryAttribute"/> class.</summary> |
| 59 | + /// <param name="type">The Objective-C type to extend. This must be a subclass of <see cref="Foundation.NSObject"/> (or <see cref="Foundation.NSObject"/> itself).</param> |
20 | 60 | public CategoryAttribute (Type type) |
21 | 61 | { |
22 | 62 | Type = type; |
23 | 63 | } |
24 | 64 |
|
25 | | - /// <summary>The type that this category extends.</summary> |
26 | | - /// <value> |
27 | | - /// </value> |
28 | | - /// <remarks> |
29 | | - /// </remarks> |
| 65 | + /// <summary>Gets or sets the type that this category extends.</summary> |
| 66 | + /// <value>The type this category extends.</value> |
30 | 67 | public Type Type { get; set; } |
31 | | - /// <summary>The name of the category.</summary> |
32 | | - /// <value> |
33 | | - /// </value> |
34 | | - /// <remarks> |
35 | | - /// <para>This must be a valid Objective-C type name, but is otherwise unused.</para> |
36 | | - /// </remarks> |
37 | | - public string Name { get; set; } |
| 68 | + |
| 69 | + /// <summary>Gets or sets the name of the category.</summary> |
| 70 | + /// <value>The category name, or <see langword="null"/> to use the managed type name.</value> |
| 71 | + /// <remarks> |
| 72 | + /// <para>This must be a valid Objective-C type name, but is otherwise unused.</para> |
| 73 | + /// </remarks> |
| 74 | + public string? Name { get; set; } |
38 | 75 | } |
39 | 76 | } |
0 commit comments