Other language features as objects

So, continuing on the thread of Everything is an object, let’s look at other items in the C# language that you might want as an object.


References.   See our previous work on IReference & friends for an example of how this can be powerful.


Expressions.  Suppose you could do:


     Expression e = new Expression (1 + 2);

     int x = e.Evaluate();


     q = customers.select (zipcode = 90210);


Note that I don’t pass a string here; I really pass a C# expression.  We see something like this with anonymous methods, but I’m going a bit further here.


Got any other ideas?

Comments (3)

  1. Sean says:

    You already covered Methods as objects, but I had some thoughts on that..(http://sleepyhead.homedns.org/blogs/smac/archive/2004/06/08/164.aspx)

    Fields in the same vein perhaps?

    Field f = new Field(Type string);

    FooClass.Fields.Add(f, Field.Protected | Field.Internal)

    Though these types of things boil down to having every type be a dynamic type with language support for the functionality that System.Reflection provides, and the ability to modify types on the fly, which changes the instances of those types (if possible)

    Umm.. modifiers as objects?

    public, protected, internal, private all extend IModifier

    VisibleOnlyToCoolDudes : IModifier


    public override bool IsVisible()


    if (System.Threading.Thread.CurrentPrincipal.IsInRole("Cool Dudes")

    return true;

    return false;



    ?? unsure of the usefulness.. and instances of classes can be restricted with security demands/PrincipalPermission, maybe a better example…

    ProtectedNotMutable : IModifier {…}

    would have some attributes to specify certain things…

    ModiferUsageAttribute( ModifierTargets.Field | ModifierTargets.Method | ModifierTargets.Property | ModifierTargets.Class )

  2. Sean says:

    actually, the new ‘sealed’ class modifier available in 2.0 is a great example of how this might be useful..??

  3. Classes as objects? This would allow defining/modifying classes at runtime:

    Class c1 = MyClass1;

    Class c2 = MyClass2;

    Class c3 = MyClass3;

    // Concatenate two classes together

    MyCatenateClass newClass = c1 + c2;

    // Create a composite

    c3.AddChildren(new Class[]{c1, c2});

    // newClass is now c2 which derives from c1

    MyNewClass newClass = c2.DeriveFrom(c1);

    // newClass2 is now c2 which implements IInterface by automatically

    // delegating calls to objectThatImplementsIInterface

    MyNewClass newClass2 = c2.AddImplementation(IInterface, objectThatImplementsIInterface);

    Not sure if it would be very useful though 🙂 In the mind of someone used to C++-like typing this feels like the ultimate chaos… Maybe it could be used to create interesting evolutionary simulations?

    Don’t know of any programming languages that have features like this. Maybe Kevo?

Skip to main content