FirebaseExtensions 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FirebaseExtensions --version 1.0.1                
NuGet\Install-Package FirebaseExtensions -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FirebaseExtensions" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FirebaseExtensions --version 1.0.1                
#r "nuget: FirebaseExtensions, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. 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.
  2. 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 or documentReference parameters are null, the SetValueAsync methods return a failed Result 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 100 6/14/2024
1.0.1 79 6/6/2024
1.0.0 82 5/31/2024