Class FirestoreEnumNameConverter<T> (2.3.1)

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.

Inheritance

Object > FirestoreEnumNameConverter<T>

Implements

IFirestoreConverter<T>

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.