コード例 #1
0
ファイル: Compiler.cs プロジェクト: chartly/flood
        public void CompileApi(string outputPath)
        {
            using (var emptyAssemblyPaths = new TemporaryAssemblyPaths())
            using (var apiAssemblyPaths = new TemporaryAssemblyPaths())
            {
                CreateEmptyAssembly(emptyAssemblyPaths.DllPath);

                var weaver = new AssemblyWeaver(emptyAssemblyPaths.DllPath);
                var types = RpcTypes.Select(t => t.FullName);
                weaver.CopyTypes(destAssemblyPath, types);
                weaver.Write(apiAssemblyPaths.DllPath);

                var references = weaver.GetReferences();

                CompileIntoAssembly(apiAssemblyPaths.DllPath, outputPath, references);
            }
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: chartly/flood
        private void CompileIntoAssembly(string destPath, string outputPath, HashSet<string> references)
        {
            outputPath = Path.GetFullPath(outputPath);

            using (var generatedAssembly = new TemporaryAssemblyPaths())
            {

                FieldsToProperties(destPath, outputPath);

                CodeDomProvider provider = new CSharpCodeProvider();
                CompilerParameters cp = new CompilerParameters()
                {
                    GenerateExecutable = false,
                    OutputAssembly = generatedAssembly.DllPath,
                    IncludeDebugInformation = true,
                    CompilerOptions = "/unsafe"
                };

                references.Add(outputPath);
                foreach (var @ref in references)
                    cp.ReferencedAssemblies.Add(@ref);

                CompilerResults cr = provider.CompileAssemblyFromFile(cp, GeneratedFiles.ToArray());

                if (cr.Errors.HasErrors)
                {
                    var message = new StringBuilder();
                    message.Append("Error compiling generated files.\n");
                    foreach(var error in cr.Errors)
                        message.AppendFormat("  {0}\n",error.ToString());
                    throw new Exception(message.ToString());
                }

                var weaver = new AssemblyWeaver(outputPath);
                weaver.MergeTypes(generatedAssembly.DllPath, DataObjectsMap);
                weaver.AddAssembly(generatedAssembly.DllPath);
                weaver.Write(outputPath);
            }
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: chartly/flood
        private void FieldsToProperties(string assemblyPath, string outputPath)
        {
            var fields = new List<FieldInfo>();
            foreach (var type in RpcTypes)
            {
                if (!Metadata.IsDataObject(type))
                    continue;

                foreach (var field in type.GetFields())
                {
                    if (field.DeclaringType != type)
                        continue;

                    if(Metadata.HasId(field))
                        fields.Add(field);
                }
            }

            var weaver = new AssemblyWeaver(assemblyPath);
            var fieldToProperties = new FieldsToProperties(weaver);
            fieldToProperties.ProcessFields(fields);
            weaver.Write(outputPath);
        }
コード例 #4
0
ファイル: FieldsToProperties.cs プロジェクト: chartly/flood
 public FieldsToProperties(AssemblyWeaver assemblyWeaver)
 {
     AssemblyWeaver = assemblyWeaver;
 }