tags:

views:

13

answers:

1

How can I instantiate an anonymous object while passing the propertynames and values as string?

new With { .SomeProperty = "Value" }

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

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.

Jekke
w00t is that a slight 'not really possible' ?
Ropstah
It's more of an "It's possible, but I wouldn't do it without a really compelling reason." VB.net is a classical, not a dynamic language. Trying to get it to behave like the latter can be processor intensive.
Jekke