From 0adc1ae78d56b52337d633f4a28ed6472a8f130b Mon Sep 17 00:00:00 2001 From: Lamparter <71598437+Lamparter@users.noreply.github.com> Date: Sat, 1 Mar 2025 19:12:58 +0000 Subject: [PATCH] `UnsafeAttribute` --- .../UnsafeAttribute.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/extensions/Riverside.Extensions.Accountability/UnsafeAttribute.cs 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; +}