예제 #1
0
        public ScriptCodeRunner(string code, Container container)
        {
            Code      = code;
            Container = container;

            Code = new ResolvingCodeGenerator(container).ResolveLines + Code;

            var optsCtor = typeof(ScriptOptions)
                           .GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
            var opts = optsCtor[0].Invoke(new object[]
            {
                string.Empty,
                ImmutableArray <MetadataReference> .Empty,
                ImmutableArray <string> .Empty,
                ScriptMetadataResolver.Default,
                SourceFileResolver.Default,
                false,
                null,
                OptimizationLevel.Debug,
                false,
                true,
                4,
                null
            }) as ScriptOptions;

            Options = opts;

            AddImportsAndReferences();
        }
예제 #2
0
        public CompiledCodeRunner(string code, Container container)
        {
            var template =
                @"
using {0};
{1}

public class Runner
{{
    public void Run(Container Container) 
    {{ 
       {2}
       {3}
    }} 
}}";

            var generator = new ResolvingCodeGenerator(container);

            var usingLines   = generator.UsingLines;
            var resolveLines = generator.ResolveLines;

            var codeForCompilation = string.Format(
                template,
                typeof(Container).Namespace,
                usingLines,
                resolveLines,
                code);

            Container   = container;
            Compilation = new CodeCompiler(codeForCompilation, container).Compilation;
        }