Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Last active July 12, 2024 22:41
Show Gist options
  • Save bradwilson/ddcbd2ce591c669b7e0b843fd3fba1c4 to your computer and use it in GitHub Desktop.
Save bradwilson/ddcbd2ce591c669b7e0b843fd3fba1c4 to your computer and use it in GitHub Desktop.
Polyfill for `required` property support
#if !NET7_0_OR_GREATER
namespace System.Runtime.CompilerServices
{
/// <summary/>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
internal sealed class RequiredMemberAttribute : Attribute
{ }
/// <summary/>
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
internal sealed class CompilerFeatureRequiredAttribute(string featureName) : Attribute
{
/// <summary/>
public string FeatureName { get; } = featureName;
/// <summary/>
public bool IsOptional { get; set; }
}
}
namespace System.Diagnostics.CodeAnalysis
{
/// <summary/>
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
internal sealed class SetsRequiredMembersAttribute : Attribute
{ }
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment