Firestore API - Interface IFirestoreConverter<T> (3.6.0)

public interface IFirestoreConverter<T>

Reference documentation and code samples for the Firestore API interface IFirestoreConverter

Custom converter used during serialization and deserialization.

Namespace

Google.Cloud.Firestore

Assembly

Google.Cloud.Firestore.dll

Type Parameter

NameDescription
T

The type of object to convert.

Remarks

This can be specified using ConverterType to use the custom converter for all values of the attributed type, or using ConverterType to use the custom converter for a single property. The latter approach can also be used to allow for conversion of types you don't control (e.g. to serialize Guid properties as strings).

This interface is never passed a null value and should never return a null value. Null values are transparently handled by the serialization framework; if a document contains a null value, that will always be deserialized to a null reference (or null value of a nullable value type).

Converters express their conversions in terms of regular .NET types: strings, integers, lists, dictionaries and so on. The result of serializing an object of type T is then processed by the default serialization handling into the Firestore protocol buffer representation. Deserialization works the same way: first the Firestore protocol buffer representation is converted into .NET types in the default manner for this library, and the result is passed to the converter. Note that this means there can be asymmetry between serialization and deserialization: if the ToFirestore(T) method returns an int, deserializing the result will involve the FromFirestore(object) method receiving an long value as that's the default .NET representation of a Firestore integer.

Converters that intend to convert objects into top-level documents should return a string-keyed dictionary of values from ToFirestore(T). On deserialization, FromFirestore(object) will be passed a value implementing IDictionary<TKey, TValue> with a key type of string and a value type of object.

Methods

FromFirestore(object)

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)

object ToFirestore(T value)

Converts a value to its Firestore representation.

Parameter
NameDescription
valueT

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

Returns
TypeDescription
object

The converted value. Must not be null.