Firestore API - Class FirestoreEnumNameConverter<T> (3.5.0)

public sealed class FirestoreEnumNameConverter<T> : IFirestoreConverter<T> where T : struct, Enum

Reference documentation and code samples for the Firestore API class FirestoreEnumNameConverter

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.

Inheritance

object > FirestoreEnumNameConverter<T>

Implements

IFirestoreConverter

Namespace

Google.Cloud.Firestore

Assembly

Google.Cloud.Firestore.dll

Type Parameter

NameDescription
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
NameDescription
valueobject

The value to convert. When called by Google.Cloud.Firestore, this will never be null.

Returns
TypeDescription
T

The converted value. Must not be null.

ToFirestore(T)

public object ToFirestore(T value)

Converts an enum value to its name.

Parameter
NameDescription
valueT

The value to convert.

Returns
TypeDescription
object

The name of the value.

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
TypeDescription
ArgumentException

The given value is not a named value within the enum.