Beispiel #1
0
        public void DoStatement <T>(T instance, ReadOnlyCollection <string> input, bool promoteQuotes)
        {
            LexListBuilder ll = new LexListBuilder();
            Action <T>     act;

            ll.AddAndPromoteQuotes(@"
          partial class `Type 
          {
            public void DoStatement () { ", "Type", typeof(T));
            foreach (string line in input)
            {
                if (promoteQuotes)
                {
                    ll.AddAndPromoteQuotes(line);
                }
                else
                {
                    ll.Add(line);
                }
            }
            ll.AddAndPromoteQuotes("}}");
            AddMethodsAndFields(ll.ToLexList(), true).GetAction <T>("DoStatement", out act);
            try {
                act(instance);
            } catch (Exception ex) {
                ll.ToLexList().ThrowException("This did not run: " + ex.Message);
            }
        }
Beispiel #2
0
        public R DoExpression <T, R>(T instance, ReadOnlyCollection <string> input, bool promoteQuotes)
        {
            LexListBuilder ll = new LexListBuilder();
            Func <T, R>    fn;

            ll.AddAndPromoteQuotes(@" 
          partial class `Type
          {
            public `ReturnType `MethodName() { return ", "Type", typeof(T), "ReturnType", typeof(R), "MethodName", DoExpressionName);
            foreach (string line in input)
            {
                if (promoteQuotes)
                {
                    ll.AddAndPromoteQuotes(line);
                }
                else
                {
                    ll.Add(line);
                }
            }
            ll.AddAndPromoteQuotes(" ;  }}");
            AddMethodsAndFields(ll.ToLexList(), true).GetFunc <T, R>(DoExpressionName, out fn);
            try {
                return(fn(instance));
            } catch (Exception ex) {
                ll.ToLexList().ThrowException("This did not run: " + ex.Message);
                return(default(R));
            }
        }
Beispiel #3
0
        private void MakeFieldInitialiser(List <CompileMethod> currentListOfMethods)
        {
            LexListBuilder lb = new LexListBuilder();

            lb.AddAndPromoteQuotes("public void FieldsInitialiser () { ");
            lb.AddAndPromoteQuotes("if (Fields == null) Fields = new List<object> () ;");
            foreach (var f in (from f in MadeFieldsDict orderby f.Value.Index select f))
            {
                Type theType = f.Value.VarType;
                lb.AddAndPromoteQuotes("`type `name ;  if (Fields.Count == `index) Fields.Add ( (object)`name ) ; ", "type", theType, "name", f.Value.VarName, "index", f.Value.Index);
                // The conditional 'if (Fields.Count == f.Value.Index)' bit means that this initialisation function can be called repeatedly, and only the new ones will be initialised.
            }
            lb.AddAndPromoteQuotes("}");
            LexList ll = lb.ToLexList();

            ll.CrosslinkBrackets();
            CompileNextMethodHeader(ll, true, currentListOfMethods);
        }