Dreams are a fusion beetwen methods and delegates, with lots of additions, the main one being language choice.
Full reflection may be achieved using dreams instead of method, which is what Reflective# does.

In C# (importing the ReflectiveCS.dll standard library) you can declare a dream with the following syntax:
//from a delegate
Dream d = (Action) delegate {MessageBox.Show("FOO");}
d.Invoke(); //Invokes the dream
string s = d.StringDisassemble(); //returns IL opcode instructions source code
byte[] b = d.ByteDisassemble(); //returns a byte array of the instructions of the dream

//from a string of code
d = "MessageBox.Show(\"Foo\");"; //No language specified, assuming Reflective#
d.Invoke();
s = d.StringDisassemble(); //This will return IL compiled code, not the original code
s = d.Source; //This will return the original sourcecode, if available.

//from a string of code in IronPython
d = new Dream("code goes here",Language.IronPython);
d.Invoke();

The above code can be written in Reflective# in the simpler form:
//from a delegate
Dream d = {MessageBox.Show("FOO");}//Curly brackets automatically indicates a Action delegate
d(); //The invoke operator may be applied directly to the object
string s = d.StringDisassemble(); //Disassemble methods still available
byte[] b = d.ByteDisassemble();

//from a string of code
d = "MessageBox.Show(\"Foo\");"; //No language specified, assuming Reflective#
d();
s = d.StringDisassemble(); //This will return IL compiled code, not the original code
s = d.Source; //This will return the original sourcecode, if available.

//from a string of code in IronPython
d = new("code goes here",Language.IronPython);//abreviated constructor syntax
d();

For more flexibility and C# backwards compatibility, dreams may be instatiated in the same way you can declare a method.
C# Methods:
class Foo
{
    //Declare an instance method named foo
    public void foo()
    {
        Console.WriteLine("Foo");
    }
}
Reflective# Dreams:
class Foo
{
    //Declare an instance dream named foo
    public void foo()
    {
        Console.WriteLine("Foo");
    }
}
As you can see, they are declared in the same way, but here are some advantages of dreams:
class Foo
{
    //Declare an instance method named foo, that will run on its own thread
    public threaded void foo()
    {
        Console.WriteLine("Foo");
    }
    public void bar
    {
        //Return the IL source
        string original = foo.StringDisassemble();
        string name = foo.Name; //name is a MD5 sum of the properties of the dream, its footprint
        //The dream will be invoked on its own thread
        foo();
    }
}
The available languages are:
  • Brainfuck :)
  • C++
  • C#
  • F#
  • IL
  • IronPython
  • IronRuby
  • JavaScript (Jint)
  • JScript (Microsoft implementation)
  • Lua
  • Reflective#
  • VisualBasic

Dreams and Class descriptors are the main pillars of Reflective#, granting full built-in reflection.

Last edited Feb 18, 2012 at 5:26 PM by matheus2740, version 5

Comments

No comments yet.