Using system; using system.windows.forms;
Namespace arli.commonprj {public class showaboutbox {public static void showon (form fm) {messagebox.show ("ok");}}}
Post-compiled file name called AboutBox.dll
The mode call method is as follows:
// Define file name fileinfo aboxfile = new fileinfo (path.combine (application.startuppath, "aboutbox.dll");
If (Aboxfile.exists) {// If there is try {// prevent accident, such as without incomplete, illegal DLL // start load assembly abox = askEMBLY.LOADFROM (Aboxfile.FullName); type [] _t = Abox. Gettypes (); // Get all Type Foreach {// Traverse // If you find name space and class name, IF (t.namespace == "arli.commonprj" && t.name == "Showaboutbox") {// load method methodinfo m = t.getMethod ("showon"); if (m! = Null) {// If the method to be loaded exists // creates an instance Object O = Activator.createInstance T); // Execute the method, the next THIS is the parameter M.Invoke (O, New Object [] {this});} else {// loaded method does not have MessageBox.show ("File /" AboutBox. DLL / "invalid! / n / nmethod error.");} return;}} messagebox.show ("file /"aboutbox.dll/" INVALID! / N / NASSEMBLY NAME ERROR. ");} // file, name The space, method is consistent, but execute the DLL content error CATCH ("file /"aboutbox.dll/" invalid! ");} // File is abnormal DLL Catch (Exception EX) {MessageBox.show ("file /"aboutbox.dll/" error: / n / n " ex.Message);}} else {// file did not find MessageBox.show (" file /"aboutbox.dll/ "Missing ! ");
Note 1: If you use Type T = GetType ("arli.comm ...") but if this class does not exist, Exception Description 2: This reverse reflection dynamic load does not need to define accessories information Description 3 : This method has the largest possible potential detection unless non-legitimate WINDLL (such as download is incomplete), it will not enter a very slow TRY CATCH.