-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: serialize and deserialize enums #47
base: master
Are you sure you want to change the base?
fix: serialize and deserialize enums #47
Conversation
Thank you for your pull request. I'm sorry, but I can't merge this as it is. public class Data
{
[Converter(typeof(EnumStringConverter))]
TypeEnum Type { get; set; }
} |
Thank you for your answer. Why do you prefer ints rather than strings? If I do support for custom ConverterAttribute for converting types to other types: at first the value will be converted to another type by Converter and then will be converted to native type by FieldValueExtensions.ToNativeFieldValue. |
Being able to convert between string and enum would be an absolute dream since that would allow for great compatibility with databases that also interact with typescript projects which use string unions as the equivalent. This couldn't come sooner! |
I'd rather have Enums as strings in Firestore, but I can see value in storing enums as numbers.
Having a Converter for this would allow much broader customisation, but whether these are .Net Converters or a custom converter type (like JSON.NET) is a decision to be made. In my mind, a converter should convert to and from the underlying representation, and the library should expose functionality to handle known cases. |
I have updated this library. After all, I decided enum is converted to integer by default because of the fallowing reasons.
But I have implemented the EnumStringConverter which simply converts enum to string by ToString. Usage: public class Data
{
[DocumentConverter(typeof(EnumStringConverter))]
TypeEnum Type { get; set; }
} You can create a custom converter in the same way as |
Thank you, this is really nice 🔥🔥😋 |
Fix the Enums support.
Fix some misspellings.
Now they're saved in FireStore as strings.
This fixes #46