I am retrieving a list of users from Firebase but they are coming in as KVP.
{[FirstName, Eric]}
{[LastNae, EricLastName]}
{[Email, [email protected]]}
{[Phone, 12345]}
I need to convert this list of KVP to a list of Object Type named Person Class
Person
{
string FirstName {get; set;}
string LastName {get; set;}
string Email {get; set;}
string Phone {get; set;}
}
What is the most quick and efficient way of doing so:
2
Answers
Not sure how the rest of your backend is architected but you can try something like using LINQ to create a new Person object for each KVP you obtained from Firebase.
If you don’t want to use LINQ though, you can store all the KVPs in a list and iterate through them, and then map the key-value pairs to the properties of the Person class. I would personally choose LINQ implementation though as it makes the code cleaner.
Something like the one below would work as well. This includes iterating through your dictionary and assigning values to
Person
object.