From a86f0763216b87c37e09b0aab707fe9cb72c996c Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 7 Dec 2022 18:32:40 +0100 Subject: C#: Expose attribute properties and add documentation - Exposes the properties of C# attribute so they can be accessed from reflection, renaming them to PascalCase to follow .NET conventions. - Added some documentation to the newly exposed members. - Made attribute properties readonly to avoid giving the impression that they could be modified. --- .../Core/Attributes/AssemblyHasScriptsAttribute.cs | 21 +++++++++++++++++---- .../GodotSharp/Core/Attributes/ExportAttribute.cs | 21 ++++++++++++++------- .../Core/Attributes/ExportCategoryAttribute.cs | 7 +++++-- .../Core/Attributes/ExportGroupAttribute.cs | 17 +++++++++++++---- .../Core/Attributes/ExportSubgroupAttribute.cs | 17 +++++++++++++---- .../GodotSharp/Core/Attributes/RPCAttribute.cs | 6 +++--- .../Core/Attributes/ScriptPathAttribute.cs | 3 +++ 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs index b7d633517a..acdae83d2e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs @@ -1,20 +1,32 @@ using System; +using System.Diagnostics.CodeAnalysis; #nullable enable namespace Godot { /// - /// An attribute that determines if an assembly has scripts. If so, what types of scripts the assembly has. + /// Attribute that determines that the assembly contains Godot scripts and, optionally, the + /// collection of types that implement scripts; otherwise, retrieving the types requires lookup. /// [AttributeUsage(AttributeTargets.Assembly)] public class AssemblyHasScriptsAttribute : Attribute { + /// + /// If the Godot scripts contained in the assembly require lookup + /// and can't rely on . + /// + [MemberNotNullWhen(false, nameof(ScriptTypes))] public bool RequiresLookup { get; } + + /// + /// The collection of types that implement a Godot script. + /// public Type[]? ScriptTypes { get; } /// - /// Constructs a new AssemblyHasScriptsAttribute instance. + /// Constructs a new AssemblyHasScriptsAttribute instance + /// that requires lookup to get the Godot scripts. /// public AssemblyHasScriptsAttribute() { @@ -23,9 +35,10 @@ namespace Godot } /// - /// Constructs a new AssemblyHasScriptsAttribute instance. + /// Constructs a new AssemblyHasScriptsAttribute instance + /// that includes the Godot script types and requires no lookup. /// - /// The specified type(s) of scripts. + /// The collection of types that implement a Godot script. public AssemblyHasScriptsAttribute(Type[] scriptTypes) { RequiresLookup = false; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs index 3d204bdf9f..a48d79091f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs @@ -3,23 +3,30 @@ using System; namespace Godot { /// - /// An attribute used to export objects. + /// Exports the annotated member as a property of the Godot Object. /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportAttribute : Attribute { - private PropertyHint hint; - private string hintString; + /// + /// Optional hint that determines how the property should be handled by the editor. + /// + public PropertyHint Hint { get; } + + /// + /// Optional string that can contain additional metadata for the . + /// + public string HintString { get; } /// /// Constructs a new ExportAttribute Instance. /// - /// A hint to the exported object. - /// A string representing the exported object. + /// The hint for the exported property. + /// A string that may contain additional metadata for the hint. public ExportAttribute(PropertyHint hint = PropertyHint.None, string hintString = "") { - this.hint = hint; - this.hintString = hintString; + Hint = hint; + HintString = hintString; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs index 101e56f8d3..2ae55acd3e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs @@ -8,7 +8,10 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportCategoryAttribute : Attribute { - private string name; + /// + /// Name of the category. + /// + public string Name { get; } /// /// Define a new category for the following exported properties. @@ -16,7 +19,7 @@ namespace Godot /// The name of the category. public ExportCategoryAttribute(string name) { - this.name = name; + Name = name; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs index 3bd532cec1..82bd446640 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Godot { /// @@ -8,8 +10,15 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportGroupAttribute : Attribute { - private string name; - private string prefix; + /// + /// Name of the group. + /// + public string Name { get; } + + /// + /// If provided, the prefix that all properties must have to be considered part of the group. + /// + public string? Prefix { get; } /// /// Define a new group for the following exported properties. @@ -18,8 +27,8 @@ namespace Godot /// If provided, the group would make group to only consider properties that have this prefix. public ExportGroupAttribute(string name, string prefix = "") { - this.name = name; - this.prefix = prefix; + Name = name; + Prefix = prefix; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs index 2ae6eb0b68..3282b466f6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Godot { /// @@ -8,8 +10,15 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportSubgroupAttribute : Attribute { - private string name; - private string prefix; + /// + /// Name of the subgroup. + /// + public string Name { get; } + + /// + /// If provided, the prefix that all properties must have to be considered part of the subgroup. + /// + public string? Prefix { get; } /// /// Define a new subgroup for the following exported properties. This helps to organize properties in the Inspector dock. @@ -18,8 +27,8 @@ namespace Godot /// If provided, the subgroup would make group to only consider properties that have this prefix. public ExportSubgroupAttribute(string name, string prefix = "") { - this.name = name; - this.prefix = prefix; + Name = name; + Prefix = prefix; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs index fb37838ffa..afee926464 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs @@ -19,17 +19,17 @@ namespace Godot /// /// If the method will also be called locally; otherwise, it is only called remotely. /// - public bool CallLocal { get; set; } = false; + public bool CallLocal { get; init; } = false; /// /// Transfer mode for the annotated method. /// - public MultiplayerPeer.TransferModeEnum TransferMode { get; set; } = MultiplayerPeer.TransferModeEnum.Reliable; + public MultiplayerPeer.TransferModeEnum TransferMode { get; init; } = MultiplayerPeer.TransferModeEnum.Reliable; /// /// Transfer channel for the annotated mode. /// - public int TransferChannel { get; set; } = 0; + public int TransferChannel { get; init; } = 0; /// /// Constructs a instance. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs index 2c8a53ae1c..f05bcdac38 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs @@ -8,6 +8,9 @@ namespace Godot [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class ScriptPathAttribute : Attribute { + /// + /// File path to the script. + /// public string Path { get; } /// -- cgit v1.2.3