BuildAndLoad() public static method

public static BuildAndLoad ( string sourcePaths, string referencePaths, string defines ) : Assembly
sourcePaths string
referencePaths string
defines string
return System.Reflection.Assembly
Ejemplo n.º 1
0
        private static int Process(Options options)
        {
            try
            {
                Console.WriteLine("- Start Process!");

                // Resolve options

                var basePath          = Path.GetFullPath(options.Path ?? ".");
                var sources           = options.Sources.Where(p => string.IsNullOrWhiteSpace(p) == false && FilterSource(options, p)).Select(p => MakeFullPath(p, basePath)).ToArray();
                var references        = options.References.Where(p => string.IsNullOrWhiteSpace(p) == false).Select(p => MakeFullPath(p, basePath)).ToArray();
                var defines           = options.Defines.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                var targetDefaultPath = @".\CodeGen\EuNet.Rpc.CodeGen.cs";
                var targetPath        = MakeFullPath(options.TargetFile ?? targetDefaultPath, basePath);

                if (options.TargetFile == null)
                {
                    DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(targetDefaultPath));
                    if (di.Exists == false)
                    {
                        di.Create();
                    }
                }

                // Build source and load assembly
                Console.WriteLine("- Build sources");

                var assembly = AssemblyLoader.BuildAndLoad(sources, references, defines);
                if (assembly == null)
                {
                    Console.WriteLine("Fail to AssemblyLoader.BuildAndLoad");
                    return(1);
                }

                // Generate code

                Console.WriteLine("- Generate code");

                var codeGenerator = new EntryCodeGenerator(options);
                var sourceTypes   = GetTypesSafely(assembly).OrderBy(t => t.FullName).ToArray();
                codeGenerator.GenerateCode(sourceTypes);

                // Save generated code

                Console.WriteLine("- Save code");

                if (codeGenerator.CodeWriter.WriteAllText(targetPath, true) == false)
                {
                    Console.WriteLine("Nothing changed. Skip writing.");
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in processing:\n" + e);
                return(1);
            }
        }
Ejemplo n.º 2
0
        private static int Process(Options options)
        {
            try
            {
                Console.WriteLine("Start Process!");

                // Resolve options

                var basePath          = Path.GetFullPath(options.Path ?? ".");
                var sources           = options.Sources.Where(p => string.IsNullOrWhiteSpace(p) == false && FilterSource(options, p)).Select(p => MakeFullPath(p, basePath)).ToArray();
                var references        = options.References.Where(p => string.IsNullOrWhiteSpace(p) == false).Select(p => MakeFullPath(p, basePath)).ToArray();
                var targetDefaultPath = options.UseSlimClient
                    ? @".\Properties\Akka.Interfaced.CodeGen.Slim.cs"
                    : @".\Properties\Akka.Interfaced.CodeGen.cs";
                var targetPath = MakeFullPath(options.TargetFile ?? targetDefaultPath, basePath);

                // Build source and load assembly

                Console.WriteLine("- Build sources");

                var assembly = AssemblyLoader.BuildAndLoad(sources, references, options.Defines.ToArray());
                if (assembly == null)
                {
                    return(1);
                }

                // Generate code

                Console.WriteLine("- Generate code");

                var codeGenerator = new EntryCodeGenerator(options);
                var sourceTypes   = GetTypesSafely(assembly).OrderBy(t => t.FullName).ToArray();
                codeGenerator.GenerateCode(sourceTypes);

                // Save generated code

                Console.WriteLine("- Save code");

                if (codeGenerator.CodeWriter.WriteAllText(targetPath, true) == false)
                {
                    Console.WriteLine("Nothing changed. Skip writing.");
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in processing:\n" + e);
                return(1);
            }
        }