开发者

Anonymous object properties by string?

开发者 https://www.devze.com 2022-12-22 14:41 出处:网络
How can I开发者_Go百科 instantiate an anonymous object while passing the propertynames and values as string?

How can I开发者_Go百科 instantiate an anonymous object while passing the propertynames and values as string?

new With { .SomeProperty = "Value" }

new With { ".SomeProperty" = "Value" } //something like this? :)


There's no easy way to do this in VB.net. The JIT compiler doesn't keep the method names intact in the MSIL code, only in the metadata.

You can do this using the System.Reflection namespace and searching the metadata for a method by the name passed. It's fairly expensive, though.

0

精彩评论

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

关注公众号