开发者

How can I instantiate an instance of a type using a dictionary of property names/values?

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜