When calling off, we find that the number of Office2003 is different from the number of method parameters of Office2000, which leads us that we cannot call this method using normal means, and use reflection technology to easily solve the problem. The following is a simple prototype that I wrote the application reflection technology call object method. using System; using System.Reflection; public class Invoker {public static void Main () {System.Type myType = System.Type.GetType ( "Demo"); // acquiring system type object obj = Assembly.GetAssembly (myType). CreateInstance ("demo"); // Create an instance methodInfo method ("printline"); // extraction method information method.invoke (Obj, new object [] {"rookie", 27}); // Call Method method = mytype.getMethod ("printline2"); // Extract another method, actual application to get the same method according to different versions, and construct a different parameter array method.invoke (Obj, new object [] {"rookie" , 27, "Rookie Personal Information."}); // Call Method}} PUBLIC CLASS DEMO {PUBLIC CLIC DEMO () {} // Puble Void Printline (String Name, Int Age) {System. Console.writeline ("Name =" Name "; AGE =" Age.toTRING ());} // The method of upgrading version in the actual application (the same name is the same, only the number of parameters is different) public void printline2 (String Name) , Int Age, string description) {system.console.writeline ("name =" name "; age =" Age.toTRING () "; Description =" description);}}
Regarding this article, please click Http://202.102.53.36/User3/rookieport/main.asp?id=1377826