0

I'm using firebase for c# xamarin and I want to do for each user it will check if he has counter, and if not it will generate for him. I tried it like this:

try
{
    FirebaseResponse resp = await client.GetAsync(uid+"/counter/node");
    result = resp.ResultAs<Counter_Class>();
}
catch
{
    var counter = new Counter_Class
    {
        cnt = "0"
    };
    SetResponse response = await client.SetAsync(uid + "counter/node", counter);
    Counter_Class result = response.ResultAs<Counter_Class>(); //The response will contain the data written
}

When the child exists the try/catch is fine but when it doesn't and the catch need to generate a child it shut down. can I check if the child exists like `if(childexists)? I'm using c# not java

  • 1
    Possible duplicate of [Google firebase check if child exists](https://stackoverflow.com/questions/37397205/google-firebase-check-if-child-exists) – Mikev Mar 19 '19 at 12:37
  • No, I need it in c# – SimplyBoost Mar 19 '19 at 12:38
  • It seems like the [FireSharp library](https://github.com/ziyasal/FireSharp/blob/c361b28baa40d03d0518387eb28e21b595ebb269/FireSharp.Core/Response/FirebaseResponse.cs) that you use doesn't implement `HasChild` that the linked answer depends on. – Frank van Puffelen Mar 19 '19 at 13:13
  • I dont need the code to be with the firesharp library i need just a code that matches c# xamarin – SimplyBoost Mar 19 '19 at 16:09

0 Answers0