Maksim Vi. Maksim Vi. - 1 month ago 5
ASP.NET (C#) Question

Asp.Net Deserialize Dictionary<string, object> to an object

What would be the best way to deserialize this

Dictionary<string, object>{
{"fName", "John"},
{"lName", "Doe"},
{"email", "john@doe.net"}
}


to this

class Member{
string fName;
string lName;
string email;
}

Answer

This isn't really serialization in the normal sense, that usually refers to taking some disk or network formatted data (binary, ASCII, JSON etc) and loading it into a runtime object.

However, if I understand you correctly, I think what you are trying to do is...

public Member( Dictionary<string,object> dictionary )
{ 
    fName = dictionary["fName"];
    lName = dictionary["lName"];
    email = dictionary["email"];
}

// usage Member m = new Member( inputDictionary );