Invoke, , .
MyClass master= new MyClass();
master.GetType().GetMethod("HelloWorld").Invoke(objMyClass, null);
, (Overloaded method). , , , .
MyClass master= new MyClass();
MethodInfo mInfo = master.GetType().GetMethods().FirstOrDefault
(method => method.Name == "HelloWorld"
&& method.GetParameters().Count() == 0);
mInfo.Invoke(objMyClass, null);
, , . Type.GetType
Type type = Type.GetType("YourNamespace.MyClass");
object objMyClass = Activator.CreateInstance(type);
MethodInfo mInfo = objMyClass.GetType().GetMethods().FirstOrDefault
(method => method.Name == "HelloWorld"
&& method.GetParameters().Count() == 0);
mInfo.Invoke(objMyClass, null);
, Type.GetType null. Type.GetType
public Type GetTheType(string strFullyQualifiedName)
{
Type type = Type.GetType(strFullyQualifiedName);
if (type != null)
return type;
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
type = asm.GetType(strFullyQualifiedName);
if (type != null)
return type;
}
return null;
}
Type type = GetTheType("YourNamespace.MyClass");