コード例 #1
0
        public void CompileAndBuildModule(string filename, string outputAssembly)
        {
            // Compile the file
            var compilerContext = Compile(filename);

            // Insert derived class methods
            foreach (var method in compilerContext.MethodDefinitions)
            {
                var systemMethodName = SystemFunctionToMethodInfoFactory
                                       .GetSystemMethodName(method.Key);

                // System method overrides need a slightly different definition
                if (!string.IsNullOrWhiteSpace(systemMethodName))
                {
                    method.Value.Statements.Add(
                        new CodeMethodReturnStatement(
                            new CodeMethodInvokeExpression(
                                new CodeBaseReferenceExpression(),
                                systemMethodName)));
                }
                else
                {
                    method.Value.Statements.Add(
                        new CodeMethodReturnStatement(
                            new CodePrimitiveExpression(VclFrontendAction.NoOp)));
                }
            }

            // Create namespace Im.Proxy.Handlers
            var codeNamespace = new CodeNamespace("Im.Proxy.Handlers");

            codeNamespace.Types.Add(compilerContext.HandlerClass);

            // Create code unit
            var unit = new CodeCompileUnit();

            unit.Namespaces.Add(codeNamespace);
            unit.ReferencedAssemblies.Add(typeof(VclCompiler).Assembly.GetName().FullName);

            // TODO: Inject assembly information attributes

            // Write assembly
            var options =
                new CompilerParameters
            {
                OutputAssembly = outputAssembly
            };
            var compileResults = CodeDomProvider
                                 .CreateProvider("CSharp")
                                 .CompileAssemblyFromDom(
                options,
                unit);

            // TODO: Sign assembly using our signing key

            // Finally return assembly name
        }
コード例 #2
0
        public static CodeMemberMethod CreateSystemMethod(string methodName)
        {
            var systemMethodName = SystemFunctionToMethodInfoFactory
                                   .GetSystemMethodName(methodName);

            // Create code method
            return
                (new CodeMemberMethod
            {
                Name = systemMethodName,
                // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
                Attributes = MemberAttributes.Public | MemberAttributes.Override,
                ReturnType = new CodeTypeReference(typeof(VclFrontendAction))
            });
        }