From c38787c74923cf93d2883a8be3d3f139442f249d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 19 Feb 2026 12:41:24 +0100 Subject: [PATCH] [ObjCRuntime] Enable nullability and clean up CategoryAttribute. This is file 6 of 7 files with nullability disabled in ObjCRuntime. * Enable nullability (#nullable enable). * Add nullability-aware API updates for category name metadata. * Inline XML documentation from CategoryAttribute.xml into source and remove the include file. * Improve XML documentation formatting, grammar, and cref usage. Contributes towards https://github.com/dotnet/macios/issues/17285. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/api/ObjCRuntime/CategoryAttribute.xml | 68 ------------------- src/ObjCRuntime/CategoryAttribute.cs | 77 ++++++++++++++++------ 2 files changed, 57 insertions(+), 88 deletions(-) delete mode 100644 docs/api/ObjCRuntime/CategoryAttribute.xml diff --git a/docs/api/ObjCRuntime/CategoryAttribute.xml b/docs/api/ObjCRuntime/CategoryAttribute.xml deleted file mode 100644 index 80e9ecc63714..000000000000 --- a/docs/api/ObjCRuntime/CategoryAttribute.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - Attribute used to flag a class as a category that extends the API of another type. - - - This attribute is applied to static user code classes and will - surface all of the exported methods and properties (those that - have the ) - 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#: - - - - - - - - - If the managed class is not referenced by other managed code (and only called from Objective-C), - the managed linker will remove it. This can be avoided either by adding a - attribute to the class, or by creating a custom linker definition file. - - - Custom Linker Configuration - - \ No newline at end of file diff --git a/src/ObjCRuntime/CategoryAttribute.cs b/src/ObjCRuntime/CategoryAttribute.cs index fa2b3e9a2b80..ec9137f1f948 100644 --- a/src/ObjCRuntime/CategoryAttribute.cs +++ b/src/ObjCRuntime/CategoryAttribute.cs @@ -1,39 +1,76 @@ // -// CategoryAttribyute.cs: +// CategoryAttribute.cs: // // Authors: // Rolf Bjarne Kvinge // // Copyright 2015 Xamarin Inc. -// Disable until we get around to enable + fix any issues. -#nullable disable +#nullable enable namespace ObjCRuntime { - /// + /// Attribute used to flag a class as a category that extends another type. + /// + /// This attribute is applied to static user-code classes and surfaces all exported methods and properties (those with the ) 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 your types surfaced to Objective-C. + /// 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#: + /// + /// + /// + /// + /// + /// + /// 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 attribute to the class, or by creating a custom linker definition file. + /// See Custom Linker Configuration for more information. + /// [AttributeUsage (AttributeTargets.Class)] public class CategoryAttribute : Attribute { - /// The Objective-C type to extend. This must be a subclass of NSObject (or NSObject itself). - /// The type that this category extends. - /// - /// + /// Initializes a new instance of the class. + /// The Objective-C type to extend. This must be a subclass of (or itself). public CategoryAttribute (Type type) { Type = type; } - /// The type that this category extends. - /// - /// - /// - /// + /// Gets or sets the type that this category extends. + /// The type this category extends. public Type Type { get; set; } - /// The name of the category. - /// - /// - /// - /// This must be a valid Objective-C type name, but is otherwise unused. - /// - public string Name { get; set; } + + /// Gets or sets the name of the category. + /// The category name, or to use the managed type name. + /// + /// This must be a valid Objective-C type name, but is otherwise unused. + /// + public string? Name { get; set; } } }