public sealed class DocumentSnapshot : IEquatable<DocumentSnapshot>
An immutable snapshot of the data for a document.
Implements
IEquatable<DocumentSnapshot>Namespace
Google.Cloud.FirestoreAssembly
Google.Cloud.Firestore.dll
Properties
CreateTime
public Timestamp? CreateTime { get; }
The creation time of the document if it exists, or null otherwise.
Property Value | |
---|---|
Type | Description |
Nullable<Timestamp> |
Database
public FirestoreDb Database { get; }
The database that owns the document.
Property Value | |
---|---|
Type | Description |
FirestoreDb |
Exists
public bool Exists { get; }
Whether or not the document exists.
Property Value | |
---|---|
Type | Description |
Boolean |
Id
public string Id { get; }
The ID of the document.
Property Value | |
---|---|
Type | Description |
String |
ReadTime
public Timestamp ReadTime { get; }
The time at which this snapshot was read.
Property Value | |
---|---|
Type | Description |
Timestamp |
Reference
public DocumentReference Reference { get; }
The full reference to the document.
Property Value | |
---|---|
Type | Description |
DocumentReference |
UpdateTime
public Timestamp? UpdateTime { get; }
The update time of the document if it exists, or null otherwise.
Property Value | |
---|---|
Type | Description |
Nullable<Timestamp> |
Methods
ContainsField(FieldPath)
public bool ContainsField(FieldPath path)
Determines whether or not the given field path is present in the document. If this snapshot represents a missing document, this method will always return false.
Parameter | |
---|---|
Name | Description |
path | FieldPath The field path to check. Must not be null. |
Returns | |
---|---|
Type | Description |
Boolean | true if the specified path represents a field in the document; false otherwise |
ContainsField(String)
public bool ContainsField(string path)
Determines whether or not the given field path is present in the document. If this snapshot represents a missing document, this method will always return false.
Parameter | |
---|---|
Name | Description |
path | String The dot-separated field path to check. Must not be null or empty. |
Returns | |
---|---|
Type | Description |
Boolean | true if the specified path represents a field in the document; false otherwise |
ConvertTo<T>()
public T ConvertTo<T>()
Deserializes the document data as the specified type.
Returns | |
---|---|
Type | Description |
T | The deserialized data, or null if this object represents a missing document. |
Type Parameter | |
---|---|
Name | Description |
T | The type to deserialize the document data as. |
GetHashCode()
public override int GetHashCode()
Returns | |
---|---|
Type | Description |
Int32 |
GetValue<T>(FieldPath)
public T GetValue<T>(FieldPath path)
Fetches a field value from the document, throwing an exception if the field does not exist.
Parameter | |
---|---|
Name | Description |
path | FieldPath The field path to fetch. Must not be null. |
Returns | |
---|---|
Type | Description |
T | The deserialized value. |
Type Parameter | |
---|---|
Name | Description |
T |
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The field does not exist in the document data. |
GetValue<T>(String)
public T GetValue<T>(string path)
Fetches a field value from the document, throwing an exception if the field does not exist.
Parameter | |
---|---|
Name | Description |
path | String The dot-separated field path to fetch. Must not be null or empty |
Returns | |
---|---|
Type | Description |
T | The deserialized value. |
Type Parameter | |
---|---|
Name | Description |
T |
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | The field does not exist in the document data. |
ToDictionary()
public Dictionary<string, object> ToDictionary()
Returns the document data as a Dictionary<TKey,TValue>.
Returns | |
---|---|
Type | Description |
Dictionary<String, Object> | A Dictionary<TKey,TValue> containing the document data, or null if this object represents a missing document. |
Exceptions | |
---|---|
Type | Description |
InvalidOperationException | This snapshot represents a missing document, i.e. Exists is false. |
TryGetValue<T>(FieldPath, out T)
public bool TryGetValue<T>(FieldPath path, out T value)
Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing it if it was found.
Parameters | |
---|---|
Name | Description |
path | FieldPath The field path to fetch. Must not be null. |
value | T When this method returns, contains the deserialized value if the field was found, or the default value
of |
Returns | |
---|---|
Type | Description |
Boolean | true if the field was found; false otherwise. |
Type Parameter | |
---|---|
Name | Description |
T | The type to deserialize the value to, if it is found. |
This method does not throw an exception if the field is not found, but does throw an exception if the field was found but cannot be deserialized.
TryGetValue<T>(String, out T)
public bool TryGetValue<T>(string path, out T value)
Attempts to fetch the given field path from the document, returning whether or not it was found, and deserializing it if it was found.
Parameters | |
---|---|
Name | Description |
path | String The dot-separated field path to fetch. Must not be null or empty |
value | T When this method returns, contains the deserialized value if the field was found, or the default value
of |
Returns | |
---|---|
Type | Description |
Boolean | true if the field was found; false otherwise. |
Type Parameter | |
---|---|
Name | Description |
T | The type to deserialize the value to, if it is found. |
This method does not throw an exception if the field is not found, but does throw an exception if the field was found but cannot be deserialized.