diff --git a/src/extensions/Riverside.Extensions.Accountability/UnsafeAttribute.cs b/src/extensions/Riverside.Extensions.Accountability/UnsafeAttribute.cs new file mode 100644 index 0000000..baaa1ab --- /dev/null +++ b/src/extensions/Riverside.Extensions.Accountability/UnsafeAttribute.cs @@ -0,0 +1,41 @@ +using System.Reflection; + +namespace Riverside.Extensions.Accountability; + +/// +/// Indicates that a method, constructor, property, or field is unsafe. This class cannot be inherited. +/// +/// +/// This may imply that a method should not be used, or that a method should be used with caution. +/// +[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property | AttributeTargets.Field, Inherited = false)] +public sealed class UnsafeAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public UnsafeAttribute() + { + } + + /// + /// Initializes a new instance of the class with a specified reason. + /// + /// The reason why the member is considered unsafe. + public UnsafeAttribute(string reason) + { + Reason = reason; + } + + /// + /// The reason why the member is considered unsafe. + /// + public string? Reason { get; } + + /// + /// Determines whether the specified method is marked with the . + /// + /// The method to check. + /// true if the method is marked with the ; otherwise, false. + public static bool IsUnsafe(MethodBase method) => method.GetCustomAttribute() != null; +}