public sealed class FirestoreEnumNameConverter<T> : IFirestoreConverter<T> where T : struct, Enum
Custom converter which uses enum value names instead of integer values as the Firestore representation. This converter is not used by default; it must be configured in the same way as any other custom converter.
Implements
IFirestoreConverter<T>Namespace
Google.Cloud.FirestoreAssembly
Google.Cloud.Firestore.dll
Type Parameter | |
---|---|
Name | Description |
T | The enum type to convert |
Remarks
Currently this is always case-sensitive, with no customization of the names used. In future releases we may introduce further ways to configure this converter, but the default behavior will remain the same.
When the same enum value has multiple names, no guarantee is made about which one is returned, although both are accepted for conversion back to enum values. You are strongly encouraged not to use multiple names for the same value.
Methods
FromFirestore(Object)
public T FromFirestore(object value)
Converts a value from its Firestore representation.
Parameter | |
---|---|
Name | Description |
value | Object The value to convert. When called by Google.Cloud.Firestore, this will never be null. |
Returns | |
---|---|
Type | Description |
T | The converted value. Must not be null. |
ToFirestore(T)
public object ToFirestore(T value)
Converts an enum value to its name.
Parameter | |
---|---|
Name | Description |
value | T The value to convert. |
Returns | |
---|---|
Type | Description |
Object | The name of the value. |
If multiple values in the enum map to the same integer, it is undefined which will be returned. If the value is not a named enum element, an exception is thrown, even if the enum is decorated with FlagsAttribute.
Exceptions | |
---|---|
Type | Description |
ArgumentException | The given value is not a named value within the enum. |