How does the code looks that would create an object of class:
string myClass = 'MyClass';
Of the above type, and then call
string myMethod = 'MyMethod';
On that object?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Type.GetType(string)to get the type object.Activator.CreateInstance(Type)to create an instance.Type.GetMethod(string)to retrieve a method.MethodBase.Invoke(object, object[])to invoke the method on the objectExample, but with no error checking:
Each step needs careful checking – you may not find the type, it may not have a parameterless constructor, you may not find the method, you may invoke it with the wrong argument types.
One thing to note: Type.GetType(string) needs the assembly-qualified name of the type unless it’s in the currently executing assembly or mscorlib.