Skip to content

Instantly share code, notes, and snippets.

@davidboothe
Created June 28, 2022 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidboothe/95f58039d28576ed7750f9336b171c8e to your computer and use it in GitHub Desktop.
Save davidboothe/95f58039d28576ed7750f9336b171c8e to your computer and use it in GitHub Desktop.
Helpful C# Code Snippets
public static PropertyBuilder<TEnum> HasEnumConversion<TEnum>(this PropertyBuilder<TEnum> propertyBuilder)
where TEnum : struct, Enum
{
return propertyBuilder.HasConversion(
enumValue => $"{enumValue}",
enumString => Enum.Parse<TEnum>(enumString)
);
}
//Usage
builder.Property(e => e.EntityType).HasEnumConversion();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment