J
John
I am confused how to cast to a type which is obtained from reflection:
Normally, this is what we do:
using ABC;
....
if (obj is ABC.MyClass)
{
((ABC.MyClass)obj).MyProperty = "value";
}
but now I want to obtain the type of ABC.MyClass from reflection, like this:
using System.Reflection;
....
Assembly objAssembly = Assembly.Load("ABC");
Type t = objAssembly.GetType("ABC.MyClass");
if (obj is t)
{
((t)obj).MyProperty = "value";
}
It will raise compile error: The type or namespace name 't' could not be
found (are you missing a using directive or an assembly reference?)
Anyone can give a hint on how to deal with dynamic Type that obtained from
Assembly ?
Thanks a lot!
Normally, this is what we do:
using ABC;
....
if (obj is ABC.MyClass)
{
((ABC.MyClass)obj).MyProperty = "value";
}
but now I want to obtain the type of ABC.MyClass from reflection, like this:
using System.Reflection;
....
Assembly objAssembly = Assembly.Load("ABC");
Type t = objAssembly.GetType("ABC.MyClass");
if (obj is t)
{
((t)obj).MyProperty = "value";
}
It will raise compile error: The type or namespace name 't' could not be
found (are you missing a using directive or an assembly reference?)
Anyone can give a hint on how to deal with dynamic Type that obtained from
Assembly ?
Thanks a lot!