Dim asm As [Assembly] = [Assembly].LoadFrom( said:
Dim ty As Type = asm.GetType(<Object Name and class name>)
Dim obj As Object = Activator.CreateInstance(ty)
obj.popupmsg()
Assembly asm = Assembly.LoadFrom(<FileName>);
Type ty = asm.GetType(<Object Name and class name>);
object obj = Activator.CreateInstance(ty);
Here you run into a problem (and I didn't realize your above code would work
in VB.Net).
The obj variable is of type 'object' - and the object class obviously does
not define the popupmsg() method.
You have two options.
1) If the code you are writing contains the definition for the 'real' type
of obj, you can cast it, and then call popupmsg:
SomeType someType = obj as SomeType;
if (someType != null)
{
someType.popupmsg();
}
2) If you do not have this definition, you will have to use reflection to
access the method and call it. Note - you may need to change the flags
passed to GetMethod:
MethodInfo popupMethod = ty.GetMethod("popupmsg", BindingFlags.Instance |
BindingFlags.Public);
if (popupMethod != null)
{
popupMethod.Invoke(obj, null);
}
HTH
--
Adam Clauss
Michael said:
Hi all :
in vb.net I know use the follow code can implement dynamic call
Dim asm As [Assembly] = [Assembly].LoadFrom(<FileName>)
Dim ty As Type = asm.GetType(<Object Name and class name>)
Dim obj As Object = Activator.CreateInstance(ty)
obj.popupmsg()
how can I implement in C#
Thx