[Original] Implementing plug-in programming in C #

Source: Internet
Author: User

InProgramAfter writing the program, if we want to constantly upgrade the functions of the program and use the previous ideas to write the program, we can only add and change the main programCodeIs there no other way? The answer is yes. How can this problem be achieved? -- Plug-in!
Yes, it is the plug-in, just like our eclipse, that is, the program "built" by the plug-in, using the plug-in, we can easily add and modify the functions of the program without re-compiling the entire project. This is the benefit of using plug-in technology! Below are some of the methods I have used in actual development. I have sorted them out for your reference .... (Here is just an example of dynamically loading a class! And so on !)

/********************************** Main program **** *************************/
// Load the assembly of the class
Assembly = assembly. loadfrom ("C: \ maxun \ test. dll ");
Type type = assembly. GetType ("test. outstring ");
// Obtain the specified Method
Methodinfo met = type. getmethod ("outsuccess ");
// Create an instance
Object OBJ = system. activator. createinstance (type );
// Call Method
String strresult = (string) met. Invoke (OBJ, null );

// If this method has parameters, you can use the following methods to implement it:
/*
Object [] objarray = new object [7];
Objarray [0] = "parameter 1 ";
Objarray [1] = "parameter 2 ";
Objarray [2] = "parameter 3 ";
............

* ** Result = (***) met. Invoke (OBJ, objarray );
*/
/********************************** Class code **** *************************/
Using system;

Namespace Test
{
Public class outstring
{
Public outstring ()
{
}

Public String outsuccess ()
{
Return ("Success :)");
}
}
}
********* ******************/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.