Class FirestoreEnumNameConverter<T>
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
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public sealed class FirestoreEnumNameConverter<T> : IFirestoreConverter<T> where T : struct, Enum
Type Parameters
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)
Converts a value from its Firestore representation.
Declaration
public T FromFirestore(object value)
Parameters
Type | Name | Description |
---|---|---|
object | value | 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. |
Implements
ToFirestore(T)
Converts an enum value to its name.
Declaration
public object ToFirestore(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to convert. |
Returns
Type | Description |
---|---|
object | The name of the value. |
Implements
Remarks
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 | Condition |
---|---|
ArgumentException | The given value is not a named value within the enum. |