Click here to Skip to main content
15,894,896 members
Articles / Programming Languages / C#

GOF's Adapters and Some Magic

Rate me:
Please Sign up or sign in to vote.
3.80/5 (3 votes)
21 Apr 2009CPOL14 min read 25.1K   85   32  
How to create automated Adapters and extend/modify the original functionality with default member’s implementation for interfaces, Eiffel-like Separates, Code Injection, and Design by Contract.
using System;
using System.Collections.Generic;
using System.Text;

namespace Scaredfingers.Assertions
{
    public partial class ChacalAssertionManager
    {
        const string ALXML = @"
            <grammar xmlns=""http://tempuri.org/AL.xsd"" class=""Compiling.RecursiveParser"">
    <TerminalSymbol>
        <Symbol name=""identifier"" type=""100002"" />
        <Symbol name=""const"" type=""100004"" />
        <Symbol name=""Old"" type=""100001"" />
        <Symbol name=""forall"" type=""100001"" />
        <Symbol name=""exists"" type=""100001"" />
        <Symbol name=""in"" type=""100001"" />
        <Symbol name=""int"" type=""100001"" />
        <Symbol name=""string"" type=""100001"" />
        <Symbol name=""object"" type=""100001"" />
        <Symbol name=""bool"" type=""100001"" />
        <Symbol name=""new"" type=""100001"" />
        <Symbol name=""null"" type=""100001"" />
        <Symbol name=""is"" type=""100001"" />
        <Symbol name=""this"" type=""100001"" />
        <Symbol name=""ref"" type=""100001"" />
        <Symbol name=""out"" type=""100001"" />
        <Symbol name="";"" type=""100008"" />
        <Symbol name="","" type=""100008"" />
        <Symbol name="":"" type=""100008"" />
        <Symbol name=""("" type=""100008"" />
        <Symbol name="")"" type=""100008"" />
        <Symbol name=""="" type=""100008"" />
        <Symbol name=""+"" type=""100008"" />
        <Symbol name=""-"" type=""100008"" />
        <Symbol name=""*"" type=""100008"" />
        <Symbol name=""/"" type=""100008"" />
        <Symbol name=""%"" type=""100008"" />
        <Symbol name=""|"" type=""100008"" />
        <Symbol name=""."" type=""100008"" />
        <Symbol name=""&amp;"" type=""100008"" />
        <Symbol name=""&lt;"" type=""100008"" />
        <Symbol name=""&gt;"" type=""100008"" />
        <Symbol name=""!"" type=""100008"" />
        <Symbol name=""~"" type=""100008"" />
        <Symbol name=""["" type=""100008"" />
        <Symbol name=""]"" type=""100008"" />
    </TerminalSymbol>
    <NonTerminalSymbol>
        <NTSymbol name=""Start"" />
        <NTSymbol name=""ALExpression"" />
        <NTSymbol name=""expression"" />
        <NTSymbol name=""boolExpresion"" />
        <NTSymbol name=""boolTerm"" />
        <NTSymbol name=""boolFactor"" />
        <NTSymbol name=""term"" />
        <NTSymbol name=""factor"" />
        <NTSymbol name=""type"" />
        <NTSymbol name=""forallExp"" />
        <NTSymbol name=""existsExp"" />
        <NTSymbol name=""varDecl"" />
        <NTSymbol name=""method"" />
        <NTSymbol name=""paramlist"" />
    </NonTerminalSymbol>
    <StartSymbol name=""Start"" />
    <rules containerClass=""Assertions.AALExpression"">
        <Rule left=""[Start]"" right=""[ALExpression]"" routine=""Start"" />
        <Rule left=""[ALExpression]"" right=""[boolExpression]"" routine=""Simple"" />
        <Rule left=""[ALExpression]"" right=""[boolExpression] = &gt; [boolExpression]"" routine=""Implies"" />
        <Rule left=""[ALExpression]"" right=""[boolExpression] &lt; = &gt; [boolExpression]"" routine=""DoubleImplies"" />
        <Rule left=""[boolExpression]"" right=""[boolTerm]"" routine=""SimpleBoolTerm"" />
        <Rule left=""[boolExpression]"" right=""[boolExpression] | | [boolTerm]"" routine=""BoolOr"" />
        <Rule left=""[boolTerm]"" right=""[boolFactor]"" routine=""SimpleBoolFactor"" />
        <Rule left=""[boolTerm]"" right=""[boolTerm] &amp; &amp; [boolFactor]"" routine=""BoolAnd"" />
        <Rule left=""[boolFactor]"" right=""[factor]"" routine=""BoolFactor"" />
        <Rule left=""[boolFactor]"" right=""! [boolFactor]"" routine=""BoolNot"" />
        <Rule left=""[boolFactor]"" right=""[expression] &lt; [expression]"" routine=""LessThan"" />
        <Rule left=""[boolFactor]"" right=""[expression] &lt; = [expression]"" routine=""LessEqual"" />
        <Rule left=""[boolFactor]"" right=""[expression] &gt; [expression]"" routine=""GreaterThan"" />
        <Rule left=""[boolFactor]"" right=""[expression] &gt; = [expression]"" routine=""GreaterEqual"" />
        <Rule left=""[boolFactor]"" right=""[expression] = = [expression]"" routine=""Equal"" />
        <Rule left=""[boolFactor]"" right=""[expression] ! = [expression]"" routine=""NotEqual"" />
        <Rule left=""[boolFactor]"" right=""( [ALExpression] )"" routine=""BoolContained"" />
        <Rule left=""[boolFactor]"" right=""[factor] is [type]"" routine=""InstanceOf"" />
        <Rule left=""[expression]"" right=""[term]"" routine=""Term"" />
        <Rule left=""[expression]"" right=""[expression] + [term]"" routine=""Plus"" />
        <Rule left=""[expression]"" right=""[expression] - [term]"" routine=""Minus"" />
        <Rule left=""[expression]"" right=""[expression] | [term]"" routine=""BitwiseOr"" />
        <Rule left=""[term]"" right=""[factor]"" routine=""Factor"" />
        <Rule left=""[term]"" right=""[term] * [factor]"" routine=""Mult"" />
        <Rule left=""[term]"" right=""[term] / [factor]"" routine=""Div"" />
        <Rule left=""[term]"" right=""[term] % [factor]"" routine=""Mod"" />
        <Rule left=""[term]"" right=""[term] &amp; [factor]"" routine=""BitwiseAnd"" />
        <Rule left=""[factor]"" right=""identifier"" routine=""Identifier"" />
        <Rule left=""[factor]"" right=""this"" routine=""ThisRef"" />
        <Rule left=""[factor]"" right=""[factor] . Old"" routine=""PreExpression"" />
        <Rule left=""[factor]"" right=""const"" routine=""Const"" />
        <Rule left=""[factor]"" right=""( [expression] )"" routine=""Contained"" />
        <Rule left=""[factor]"" right=""~ [factor]"" routine=""BitwiseNot"" />
        <Rule left=""[factor]"" right=""- [factor]"" routine=""Negative"" />
        <Rule left=""[factor]"" right=""+ [factor]"" routine=""Positive"" />
        <Rule left=""[factor]"" right=""( [type] ) [expression]"" routine=""Cast"" />
        <Rule left=""[factor]"" right=""[forallExp]"" routine=""ForallCuantified"" />
        <Rule left=""[factor]"" right=""[existsExp]"" routine=""ExistsCuantified"" />
        <Rule left=""[factor]"" right=""[expression] [ [param] ]"" routine=""IndexedExpression"" />
        <Rule left=""[factor]"" right=""new [type] ( )"" routine=""EmptyCreation"" />
        <Rule left=""[factor]"" right=""new [type] ( [param] )"" routine=""ParamCreation"" />
        <Rule left=""[factor]"" right=""null"" routine=""NullFactor"" />
        <Rule left=""[factor]"" right=""[expression] . identifier"" routine=""Property"" />
        <Rule left=""[factor]"" right=""[expression] . [method]"" routine=""CualifiedCall"" />
        <Rule left=""[factor]"" right=""[method]"" routine=""SelfCall"" />
        <Rule left=""[type]"" right=""int"" routine=""Int32Type"" />
        <Rule left=""[type]"" right=""string"" routine=""StringType"" />
        <Rule left=""[type]"" right=""object"" routine=""ObjectType"" />
        <Rule left=""[type]"" right=""bool"" routine=""BooleanType"" />
        <Rule left=""[type]"" right=""identifier"" routine=""Type"" />
        <Rule left=""[type]"" right=""[type] . identifier"" routine=""TypeDotted"" />
        <Rule left=""[method]"" right=""identifier ( )"" routine=""NoParamMethod"" />
        <Rule left=""[method]"" right=""identifier ( [param] )"" routine=""ParamMethod"" />
        <Rule left=""[param]"" right=""[expression]"" routine=""FirstParam"" />
        <Rule left=""[param]"" right=""[param] , [expression]"" routine=""Parameter"" />
        <Rule left=""[forallExp]"" right=""forall ( [varDecl] : [ALExpression] )"" routine=""Forall"" />
        <Rule left=""[existsExp]"" right=""exists ( [varDecl] : [ALExpression] )"" routine=""Exists"" />
        <Rule left=""[varDecl]"" right=""[type] identifier in [expression]"" routine=""Declaration"" />
    </rules>
</grammar>
            " ;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect SunHotels
Spain Spain
I Received a Bachelor's Degree in Computer Science at the Mathematics and Computer Science Faculty, University of Havana, Cuba.

I mainly work in web applications using C# and some Javascript. Some very few times do some Java.

Comments and Discussions