Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 public FieldsToProperties(AssemblyWeaver assemblyWeaver)
 {
     AssemblyWeaver = assemblyWeaver;
 }