step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
668 stars 168 forks source link

Attribute to specify the Key (ID) #320

Open sact1909 opened 1 month ago

sact1909 commented 1 month ago

Create an attribute that allows the user to specify the Key property to use as ID when post a new object in case someone wants to use his datatype key structure as Guid, AutoEnum etc...

Example Model Class

public class TodoItem
{
    [FirebaseKey]
    public Guid ID {get;set;}
    public string Title { get; set; }
}

await firebaseClient.Child("Todo").PostAsync(new TodoItem
{
    ID = Guid.NewGuid(),
    Title = "This is a Text"
});

Result in Firebase RealTiem Database

"Todo":{
    "621e7bf1-1d39-493f-a6b1-537afb5efa41":{
      "Title":"This is a Text"
    }
}
sact1909 commented 1 month ago

I guess I could work on this if you allow me to do it