FirebaseExtensions 1.0.1
See the version list below for details.
dotnet add package FirebaseExtensions --version 1.0.1
NuGet\Install-Package FirebaseExtensions -Version 1.0.1
<PackageReference Include="FirebaseExtensions" Version="1.0.1" />
paket add FirebaseExtensions --version 1.0.1
#r "nuget: FirebaseExtensions, 1.0.1"
// Install FirebaseExtensions as a Cake Addin #addin nuget:?package=FirebaseExtensions&version=1.0.1 // Install FirebaseExtensions as a Cake Tool #tool nuget:?package=FirebaseExtensions&version=1.0.1
Firebase/FIrestore/Exstension
A library has been created to simplify data retrieval and uploading in Firestore.
FirebaseExtension Code Description
Overview
The FirebaseExtension
class provides extension methods for DocumentReference
to perform Firestore operations. These methods facilitate setting and retrieving document data asynchronously, with options for customization and error handling.
Methods
SetValueAsync Methods
SetValueAsync<T>(this DocumentReference documentReference, T value)
- Sets a document's data in Firestore.
- Parameters:
documentReference
: The document reference.value
: The value to set in the document.
- Returns: A task representing the result of the write operation.
SetValueAsync<T>(this DocumentReference documentReference, T value, SetOptions? setOptions)
- Sets a document's data in Firestore with specified set options.
- Parameters:
documentReference
: The document reference.value
: The value to set in the document.setOptions
: The options for setting the value.
- Returns: A task representing the result of the write operation.
SetValueAsync<T>(this DocumentReference documentReference, T value, CancellationToken cancellationToken)
- Sets a document's data in Firestore with a cancellation token.
- Parameters:
documentReference
: The document reference.value
: The value to set in the document.cancellationToken
: A token to monitor for cancellation requests.
- Returns: A task representing the result of the write operation.
SetValueAsync<T>(this DocumentReference documentReference, T value, SetOptions? setOptions, CancellationToken cancellationToken)
- Sets a document's data in Firestore with specified set options and a cancellation token.
- Parameters:
documentReference
: The document reference.value
: The value to set in the document.setOptions
: The options for setting the value.cancellationToken
: A token to monitor for cancellation requests.
- Returns: A task representing the result of the write operation.
GetValueAsync Methods
GetValueAsync<T>(this DocumentReference documentReference) where T : new()
- Retrieves a document's data from Firestore.
- Parameters:
documentReference
: The document reference.
- Returns: A task representing the result of the read operation.
GetValueAsync<T>(this DocumentReference documentReference, CancellationToken cancellationToken) where T : new()
- Retrieves a document's data from Firestore with a cancellation token.
- Parameters:
documentReference
: The document reference.cancellationToken
: A token to monitor for cancellation requests.
- Returns: A task representing the result of the read operation.
Error Handling
- The methods return a
Result
object that indicates the success or failure of the operation. - If the
value
ordocumentReference
parameters are null, theSetValueAsync
methods return a failedResult
with an appropriate error message. - Exceptions encountered during the operations are caught and result in a failed
Result
with the exception message.
Usage Example
var documentReference = firestoreDb.Collection("collectionName").Document("documentName");
// Setting a value
var result = await documentReference.SetValueAsync(new { Name = "John Doe", Age = 30 });
if (result.IsSuccess)
{
Console.WriteLine("Document updated successfully.");
}
else
{
Console.WriteLine($"Error: {result.Error}");
}
// Getting a value
var getResult = await documentReference.GetValueAsync<MyClass>();
if (getResult.IsSuccess)
{
var myObject = getResult.Value;
Console.WriteLine($"Document retrieved: {myObject.Name}, {myObject.Age}");
}
else
{
Console.WriteLine($"Error: {getResult.Error}");
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- FirebaseAdmin (>= 3.0.0)
- Google.Cloud.Firestore (>= 3.7.0)
- ResultPattern (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.