Skip to content

Instantly share code, notes, and snippets.

@Rene-Sackers
Created December 20, 2020 15:20
Show Gist options
  • Save Rene-Sackers/a67d35b3b92f66abb56d460dc70f9b1f to your computer and use it in GitHub Desktop.
Save Rene-Sackers/a67d35b3b92f66abb56d460dc70f9b1f to your computer and use it in GitHub Desktop.
Strong typed policies
public class Policy
{
public string Name { get; }
public Policy(string name)
{
Name = name;
}
public static implicit operator string(Policy policy) => policy.Name;
}
public static class Policies
{
private static Policy CreatePolicy([CallerMemberName] string name = null) => new(name);
public static readonly Policy EditComment = CreatePolicy();
public static readonly Policy DeleteCommand = CreatePolicy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment