Interface IFirestoreConverter<T>
Custom converter used during serialization and deserialization.
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public interface IFirestoreConverter<T>
Type Parameters
Name | Description |
---|---|
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)
Converts a value from its Firestore representation.
Declaration
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. |
ToFirestore(T)
Converts a value to its Firestore representation.
Declaration
object ToFirestore(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to convert. When called by Google.Cloud.Firestore, this will never be null. |
Returns
Type | Description |
---|---|
object | The converted value. Must not be null. |