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 o开发者_StackOverflowne-liner for this?
ex:
var obj = CantRememberWhichClass.WithDictionary(Dictionary<string, object> input);
I wonder if you mean TypeConverter.CreateInstance
? This is not universally supported, but some converters report true for GetCreateInstanceSupported
You might be thinking of PopulateObjectMembers, but the API isn't an exact match. Maybe just use reflection instead?
精彩评论