Firebase.Database.DataSnapshot

A DataSnapshot instance contains data from a FirebaseDatabase location.

Summary

A DataSnapshot instance contains data from a FirebaseDatabase location. Any time you read FirebaseDatabase data, you receive the data as a DataSnapshot.

DataSnapshots are passed to events Query.ValueChanged

, Query.ChildChanged

, Query.ChildMoved

, Query.ChildRemoved

, or Query.ChildAdded



They are efficiently-generated immutable copies of the data at a FirebaseDatabase location. They can't be modified and will never change. To modify data at a location, use a DatabaseReference reference (e.g. with DatabaseReference.SetValueAsync(object)

).

Properties

Children
IEnumerable< DataSnapshot >
Gives access to all of the immediate children of this Snapshot.
ChildrenCount
long
The number of immediate children in the this snapshot.
Exists
bool
Returns true if the snapshot contains a non-null value.
HasChildren
bool
Indicates whether this snapshot has any children
Key
string
The key name for the source location of this snapshot.
Priority
object
Returns the priority of the data contained in this snapshot as a native type.
Reference
Used to obtain a reference to the source location for this Snapshot.
Value
object
Value returns the data contained in this snapshot as native types.

Public functions

Child(string path)
Get a DataSnapshot for the location at the specified relative path.
GetRawJsonValue()
string
GetRawJsonValue() returns the data contained in this snapshot as a json serialized string.
GetValue(bool useExportFormat)
object
GetValue() returns the data contained in this snapshot as native types.
HasChild(string path)
bool
Can be used to determine if this DataSnapshot has data at a particular location
ToString()
override string
A string representing the DataSnapshot as a key, value pair.

Properties

Children

IEnumerable< DataSnapshot > Children

Gives access to all of the immediate children of this Snapshot.

Gives access to all of the immediate children of this Snapshot. Can be used in native for loops:

Details
Returns
The immediate children of this snapshot

ChildrenCount

long ChildrenCount

The number of immediate children in the this snapshot.

Exists

bool Exists

Returns true if the snapshot contains a non-null value.

Details
Returns
True if the snapshot contains a non-null value, otherwise false

HasChildren

bool HasChildren

Indicates whether this snapshot has any children

Details
Returns
True if the snapshot has any children, otherwise false

Key

string Key

The key name for the source location of this snapshot.

Priority

object Priority

Returns the priority of the data contained in this snapshot as a native type.

Returns the priority of the data contained in this snapshot as a native type. Possible return types:

  • double
  • string Note that null is also allowed.

Details
Returns
the priority of the data contained in this snapshot as a native type

Reference

DatabaseReference Reference

Used to obtain a reference to the source location for this Snapshot.

Details
Returns
A DatabaseReference corresponding to the location that this snapshot came from

Value

object Value

Value returns the data contained in this snapshot as native types.

Value returns the data contained in this snapshot as native types. The possible types returned are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON.

Details
Returns
The data contained in this snapshot as native types

Public functions

Child

DataSnapshot Child(
  string path
)

Get a DataSnapshot for the location at the specified relative path.

Get a DataSnapshot for the location at the specified relative path. The relative path can either be a simple child key (e.g. 'fred') or a deeper slash-separated path (e.g. 'fred/name/first'). If the child location has no data, an empty DataSnapshot is returned.

Details
Parameters
path
A relative path to the location of child data
Returns
The DataSnapshot for the child location

GetRawJsonValue

string GetRawJsonValue()

GetRawJsonValue() returns the data contained in this snapshot as a json serialized string.

GetRawJsonValue() returns the data contained in this snapshot as a json string.

Details
Returns
The data contained in this snapshot as json. Return null if no data.

GetValue

object GetValue(
  bool useExportFormat
)

GetValue() returns the data contained in this snapshot as native types.

GetValue() returns the data contained in this snapshot as native types. The possible types returned are:

  • bool
  • string
  • long
  • double
  • IDictionary{string, object}
  • List{object} This list is recursive; the possible types for object in the above list is given by the same list. These types correspond to the types available in JSON. If useExportFormat is set to true, priority information will be included in the output. Priority information shows up as a .priority key in a map. For data that would not otherwise be a map, the map will also include a .value key with the data.

Details
Parameters
useExportFormat
Whether or not to include priority information
Returns
The data, along with its priority, in native types

HasChild

bool HasChild(
  string path
)

Can be used to determine if this DataSnapshot has data at a particular location

Details
Parameters
path
A relative path to the location of child data
Returns
Whether or not the specified child location has data

ToString

override string ToString()

A string representing the DataSnapshot as a key, value pair.

It returns the following form: DataSnapshot { key = {Key}, value = {Value} };