I'm trying to do something rather... unique, and maybe there's a far better way to do it but... I'm doing an inversion of control(ish) system that uses extension methods to enable/disable components of the class, so before I get into more detail and confuse you, lets look at some code!
using TestComponents.CommunicationProtocols.RS232;
//this brings in the
//ConnectRS232 extension method
namespace TestMeNamespace
{
public class Test //Although this class is defined here, we extend it above
{
public void Start()
{
this.ConnectRS232(1, 9600); //calls the ConnectRS232 extension method
}
}
}
So in short, the using declaration extends Test in the same file that we DEFINE test. (inheritance would be fine as well) However there are some problems with this! first of all, the ugly requisite "this". blech. secondly it's a messy co-dependant system.
Here's what I'm attempting to achieve:
- I want a way to easily extend static methods to a class (using declarations are fine)
- I want to make statements simple: ConnectRS232();
- I want to not have to futz with partial classes if I don't have to.
- I'd be fine with using interface inheritance.
Feel free to ask me additional questions via comments but please don't post an answer unless you have an ANSWER!
Edit: In lieu of questions raised, I'm doing some JIT compilation of C#script (www.cs-script.com) in my system, and also these scripts will be mostly written by non-programmers who have been using a really "special" proprietary language for scripting for years. I want to keep things simple as hell, and a whole bunch of "this" calls look like clutter.