Created
June 28, 2022 18:34
-
-
Save davidboothe/95f58039d28576ed7750f9336b171c8e to your computer and use it in GitHub Desktop.
Helpful C# Code Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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