コード例 #1
0
 static void Main(string[] args)
 {
     RunDecorator.Run();
     RunFactory.Run();
     RunSingleton.Run();
     RunObserver.Run();
     RunFlyweight.Run();
     RunTemplate.Run();
 }
コード例 #2
0
        private ErrorList InternalCompile(ICharStream stream)
        {
            var errors = new ErrorList();
            var lexer = TemplateLexer.Create(stream);
            var tStream = new CommonTokenStream(lexer);
            var parser = new TemplateParser(tStream) {Errors = errors};
            var docResult = parser.document();

            _template = new DynamicMethod(
                string.Format("__template_{0}", Name),
                typeof (void),
                new[] {typeof (VirtualTemplate)},
                typeof (VirtualTemplate),
                true);

            var emit = _template.GetILGenerator();
            var ctx = new Context(emit) {OptimizeLevel = OptimizeLevel};
            var doc = new Document(docResult.Tree);

            try
            {
                var e = doc.Generate(ctx);
                errors.AddRange(e);
                _image = (RunTemplate) _template.CreateDelegate(typeof (RunTemplate));
                Assembly = ctx.Sink.Build();
            }
            catch (Exception e)
            {
                errors.ErrorUnhandledCompileError(e);
            }

            stream.Seek(0);
            Source = stream.ToString();

            return errors;
        }
コード例 #3
0
 public ErrorList Compile(Assembly a)
 {
     var e = new ErrorList();
     try
     {
         _template = new DynamicMethod(
             string.Format("__template_{0}", Name),
             typeof (void),
             new[] {typeof (VirtualTemplate)},
             typeof (VirtualTemplate),
             true);
         var ctx = new AssemblyContext {Generator = _template.GetILGenerator()};
         a.Copmile(ctx);
         _image = (RunTemplate) _template.CreateDelegate(typeof (RunTemplate));
         Assembly = new Assembly(a);
     }
     catch (Exception ex)
     {
         e.ErrorUnhandledCompileError(ex);
     }
     return e;
 }