Home

Awesome

RequiredStaticMembers

NuGet GitHub license

Enforce types to implement static virtual interface members

using Svee4.RequiredStaticMembers;

interface INode
{
    [Required]
    public static virtual string Color => RequiredStaticMemberAccessException.Throw(nameof(Color));
}

class GreenNode : INode
{
    // No error - property is implemented as expected
    public static string Color => "Green";
}

class BlueNode : INode
{
    // Error RSM001: Type 'BlueNode' does not implement required static member 'GetColor' from interface 'INode'
}

Why?

How do i use it?

  1. Install the package from Nuget
  2. Give a static interface member the attribute Svee4.RequiredStaticMembers.RequiredAttribute
  3. All done! A deriving type that does not implement the given member will cause an error

I have an issue or I want to participate in development

Please open an issue or discussion

Acknowledgments