Merge pull request #69869 from raulsntos/dotnet/attributes

C#: Expose attribute properties and add documentation
This commit is contained in:
Ignacio Roldán Etcheverry 2022-12-11 22:40:35 +01:00 committed by GitHub
commit 51f2d7b59f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 24 deletions

View file

@ -1,20 +1,32 @@
using System;
using System.Diagnostics.CodeAnalysis;
#nullable enable
namespace Godot
{
/// <summary>
/// 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.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
public class AssemblyHasScriptsAttribute : Attribute
{
/// <summary>
/// If the Godot scripts contained in the assembly require lookup
/// and can't rely on <see cref="ScriptTypes"/>.
/// </summary>
[MemberNotNullWhen(false, nameof(ScriptTypes))]
public bool RequiresLookup { get; }
/// <summary>
/// The collection of types that implement a Godot script.
/// </summary>
public Type[]? ScriptTypes { get; }
/// <summary>
/// Constructs a new AssemblyHasScriptsAttribute instance.
/// Constructs a new AssemblyHasScriptsAttribute instance
/// that requires lookup to get the Godot scripts.
/// </summary>
public AssemblyHasScriptsAttribute()
{
@ -23,9 +35,10 @@ namespace Godot
}
/// <summary>
/// Constructs a new AssemblyHasScriptsAttribute instance.
/// Constructs a new AssemblyHasScriptsAttribute instance
/// that includes the Godot script types and requires no lookup.
/// </summary>
/// <param name="scriptTypes">The specified type(s) of scripts.</param>
/// <param name="scriptTypes">The collection of types that implement a Godot script.</param>
public AssemblyHasScriptsAttribute(Type[] scriptTypes)
{
RequiresLookup = false;

View file

@ -3,23 +3,30 @@ using System;
namespace Godot
{
/// <summary>
/// An attribute used to export objects.
/// Exports the annotated member as a property of the Godot Object.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ExportAttribute : Attribute
{
private PropertyHint hint;
private string hintString;
/// <summary>
/// Optional hint that determines how the property should be handled by the editor.
/// </summary>
public PropertyHint Hint { get; }
/// <summary>
/// Optional string that can contain additional metadata for the <see cref="Hint"/>.
/// </summary>
public string HintString { get; }
/// <summary>
/// Constructs a new ExportAttribute Instance.
/// </summary>
/// <param name="hint">A hint to the exported object.</param>
/// <param name="hintString">A string representing the exported object.</param>
/// <param name="hint">The hint for the exported property.</param>
/// <param name="hintString">A string that may contain additional metadata for the hint.</param>
public ExportAttribute(PropertyHint hint = PropertyHint.None, string hintString = "")
{
this.hint = hint;
this.hintString = hintString;
Hint = hint;
HintString = hintString;
}
}
}

View file

@ -8,7 +8,10 @@ namespace Godot
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ExportCategoryAttribute : Attribute
{
private string name;
/// <summary>
/// Name of the category.
/// </summary>
public string Name { get; }
/// <summary>
/// Define a new category for the following exported properties.
@ -16,7 +19,7 @@ namespace Godot
/// <param name="name">The name of the category.</param>
public ExportCategoryAttribute(string name)
{
this.name = name;
Name = name;
}
}
}

View file

@ -1,5 +1,7 @@
using System;
#nullable enable
namespace Godot
{
/// <summary>
@ -8,8 +10,15 @@ namespace Godot
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ExportGroupAttribute : Attribute
{
private string name;
private string prefix;
/// <summary>
/// Name of the group.
/// </summary>
public string Name { get; }
/// <summary>
/// If provided, the prefix that all properties must have to be considered part of the group.
/// </summary>
public string? Prefix { get; }
/// <summary>
/// Define a new group for the following exported properties.
@ -18,8 +27,8 @@ namespace Godot
/// <param name="prefix">If provided, the group would make group to only consider properties that have this prefix.</param>
public ExportGroupAttribute(string name, string prefix = "")
{
this.name = name;
this.prefix = prefix;
Name = name;
Prefix = prefix;
}
}
}

View file

@ -1,5 +1,7 @@
using System;
#nullable enable
namespace Godot
{
/// <summary>
@ -8,8 +10,15 @@ namespace Godot
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ExportSubgroupAttribute : Attribute
{
private string name;
private string prefix;
/// <summary>
/// Name of the subgroup.
/// </summary>
public string Name { get; }
/// <summary>
/// If provided, the prefix that all properties must have to be considered part of the subgroup.
/// </summary>
public string? Prefix { get; }
/// <summary>
/// Define a new subgroup for the following exported properties. This helps to organize properties in the Inspector dock.
@ -18,8 +27,8 @@ namespace Godot
/// <param name="prefix">If provided, the subgroup would make group to only consider properties that have this prefix.</param>
public ExportSubgroupAttribute(string name, string prefix = "")
{
this.name = name;
this.prefix = prefix;
Name = name;
Prefix = prefix;
}
}
}

View file

@ -19,17 +19,17 @@ namespace Godot
/// <summary>
/// If the method will also be called locally; otherwise, it is only called remotely.
/// </summary>
public bool CallLocal { get; set; } = false;
public bool CallLocal { get; init; } = false;
/// <summary>
/// Transfer mode for the annotated method.
/// </summary>
public MultiplayerPeer.TransferModeEnum TransferMode { get; set; } = MultiplayerPeer.TransferModeEnum.Reliable;
public MultiplayerPeer.TransferModeEnum TransferMode { get; init; } = MultiplayerPeer.TransferModeEnum.Reliable;
/// <summary>
/// Transfer channel for the annotated mode.
/// </summary>
public int TransferChannel { get; set; } = 0;
public int TransferChannel { get; init; } = 0;
/// <summary>
/// Constructs a <see cref="RPCAttribute"/> instance.

View file

@ -8,6 +8,9 @@ namespace Godot
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class ScriptPathAttribute : Attribute
{
/// <summary>
/// File path to the script.
/// </summary>
public string Path { get; }
/// <summary>