c# - Using dynamic variables in a foreach loop declaration -
i using reflection load in assemblies , phone call methods on classes marked internal, i'm having few issues in getting code run correctly @ runtime. unfortunately of types dealing internal same class.
i have similar following:
type mytype = type.gettype("my.myclass, my.assembly, version=1.0.0.0, culture=neutral, publickeytoken=xxxxxx", true); dynamic list = mytype.getmethod("getlist").invoke(concretetype, null); foreach (dynamic item in list) { myobject info = item.getdata(); }
where:
concretetype
pre-existing object created using activator.createinstance
mytype
internal type in my.assembly dll. the method getlist
return, illustration type of list mylist<myitem>
internal above assembly. the item
variable type internal same dll, , purpose lets assume type myitem
. i able utilize reflection pull of above types (mytype
mylist
myitem
) type variable. myobject
type can access in current project when run code above, exception on foreach
loop:
invalidoperationexception: dynamic operations can performed in homogenous appdomain.
i have tried using object
or var
in place of dynamic list
compiler error because foreach
loop doesn't iterate on type object
.
i don't think there's way can utilize type
variables statically type of these variables.
searching exception error brings whole heap of irrelevant information, , such not sure how narrow downwards results.
is there way loop run @ all?
i should mention beingness coded custom drop in solution sharepoint 2013, i'm not sure if runtime environment differ because of this.
c# dynamic types foreach
No comments:
Post a Comment