i am making a IRC bot in C#, and i would like to have the feature to load plugins... for example: there would be a text file with some code in it, and then the program would import the contents of that text file AS CODE... into a function... how is this possible?
You might like to look into the CSharpCodeProvider
class. There's some example code in this question.
Other than this, there's the option of precompiling dll's and using late binding to load those at runtime.
Other than all this, you can embed a scripting engine like Lua into your program.
The short answer is, there's all sorts of options available, it depends on exactly what you're trying to achieve as to what solution is best.
In the first two examples, you'd be looking at interface programming, you'd have some interface defined in a second dll that you can compile against, then pull some predetermined name out of the assembly via reflection, and assign it to a variable of the interface type and make calls against that.
I've never used Lua, but the article I linked too should explain how to use it.
You need to look for dynamic code compilation (see http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm, http://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/article.php/c10729/, http://www.codeproject.com/KB/cs/Dynamic_Code_Generation.aspx)
Don't you think it would be better to load the plugins in as DLLs through reflection instead though? Dynamic code wouldn't be signed so you have no way of verifying that the code comes from a trusted source and, as such, could be opening up the users of your program to some very malicious code.
I suggest either using C#-script or some DLR language like IronPython (I'd prefer the latter). But, as others pointed out, it is unsafe to run any code that your program recieves - a more wise idea would be to define a contract interface, and accept the plugins (implementing that interface) in signed assemblies.
I'm doing the same thing for a MUD server. This server has both compiled plugins and code plugins like you want to use. I created my own scripting engine using CodeDom, but that was quite a hassle. I ended up switching to CS-Script. So now we are using MEF for compiled plugins and CS-Script for code plugins.
thankyou all for helping, but im looking to share code between the imported code and the main code, for example, there would be a text file, and on load of the main program, it would open that text file and load it as a function... a function that could share code like public strings and ints and activate other functions a commands and use objects etc etc... is this possible?