4.6.0 (latest) 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.1 3.4.0 3.3.0 3.2.0 3.1.0 3.0.0 2.5.0 2.4.0 2.3.1

    public interface IFirestoreConverter<T>

Reference documentation and code samples for the Firestore API interface IFirestoreConverter

<br />

Custom converter used during serialization and deserialization.

## Derived Types

[FirestoreEnumNameConverter\<T\>](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreEnumNameConverter-1)

## Namespace

[Google.Cloud.Firestore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore)

## Assembly

Google.Cloud.Firestore.dll

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `T` | The type of object to convert. |

## Remarks


This can be specified using [ConverterType](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDataAttribute#Google_Cloud_Firestore_FirestoreDataAttribute_ConverterType) to use
the custom converter for all values of the attributed type, or using [ConverterType](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestorePropertyAttribute#Google_Cloud_Firestore_FirestorePropertyAttribute_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](https://learn.microsoft.com/dotnet/api/system.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)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.IFirestoreConverter-1#Google_Cloud_Firestore_IFirestoreConverter_1_ToFirestore__0_) method returns an [int](https://learn.microsoft.com/dotnet/api/system.int32), deserializing the result will involve
the [FromFirestore(object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.IFirestoreConverter-1#Google_Cloud_Firestore_IFirestoreConverter_1_FromFirestore_System_Object_) method receiving an [long](https://learn.microsoft.com/dotnet/api/system.int64) 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)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.IFirestoreConverter-1#Google_Cloud_Firestore_IFirestoreConverter_1_ToFirestore__0_). On deserialization, [FromFirestore(object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.IFirestoreConverter-1#Google_Cloud_Firestore_IFirestoreConverter_1_FromFirestore_System_Object_) will be passed a value
implementing [IDictionary\<TKey, TValue\>](https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2) with a key type of [string](https://learn.microsoft.com/dotnet/api/system.string) and a value type
of [object](https://learn.microsoft.com/dotnet/api/system.object).

## Methods

### FromFirestore(object)

    T FromFirestore(object value)

Converts a value from its Firestore representation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://learn.microsoft.com/dotnet/api/system.object` 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)

    object ToFirestore(T value)

Converts a value to its Firestore representation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `T` The value to convert. When called by Google.Cloud.Firestore, this will never be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.object` | The converted value. Must not be null. |