-
-
Save creatigent/9e62ec2af627fbecf8dd077d3d1c0b3c to your computer and use it in GitHub Desktop.
For use with Amazon DynamoDB DataModel API for .NET. This class can be used to automagically serialize enum properties to DynamoDB, by decorating the property with the attribute [DynamoDBProperty(typeof(DynamoEnumConverter<AccountStatus>))], where "AccountStatus" is the name of the enumerated type..
This file contains 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 class DynamoEnumConverter<TEnum> : IPropertyConverter | |
{ | |
public object FromEntry(DynamoDBEntry entry) | |
{ | |
string valueAsString = entry.AsString(); | |
TEnum valueAsEnum = (TEnum)Enum.Parse(typeof(TEnum), valueAsString); | |
return valueAsEnum; | |
} | |
public DynamoDBEntry ToEntry(object value) | |
{ | |
string valueAsString = value.ToString(); | |
DynamoDBEntry entry = new Primitive(valueAsString); | |
return entry; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment