Reputation: 10397
I know how to do this "manually", that is, loop through the dictionary and assign property values using the key and reflection. I seem to recall, though, a method hanging off of one of the built-in .Net classes for creating class instances out of dictionaries. Only now I can't seem to find it and Google's not helping.
Am I imagining things or is there a one-liner for this?
ex:
var obj = CantRememberWhichClass.WithDictionary(Dictionary<string, object> input);
Upvotes: 1
Views: 72
Reputation: 1062865
I wonder if you mean TypeConverter.CreateInstance
? This is not universally supported, but some converters report true for GetCreateInstanceSupported
Upvotes: 1
Reputation: 1062865
You might be thinking of PopulateObjectMembers, but the API isn't an exact match. Maybe just use reflection instead?
Upvotes: 1