Наследование: Mono.Cecil.DefaultAssemblyResolver
Пример #1
0
 public AutoExpressionField(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
 {
     this.Assembly = assembly;
     this.Resolver = resolver;
     this.Log = log;
     this.SignumUtilities = assembly.Name.Name == "Signum.Utilities" ? assembly : resolver.SignumUtilities;
     this.ExpressionField = SignumUtilities.MainModule.GetType("Signum.Utilities", "ExpressionFieldAttribute");
 }
Пример #2
0
 public AutoExpressionField(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
 {
     this.Assembly        = assembly;
     this.Resolver        = resolver;
     this.Log             = log;
     this.SignumUtilities = assembly.Name.Name == "Signum.Utilities" ? assembly : resolver.SignumUtilities;
     this.ExpressionField = SignumUtilities.MainModule.GetType("Signum.Utilities", "ExpressionFieldAttribute");
 }
Пример #3
0
        public SymbolFixer(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;
            this.Log = log;

            this.SigumEntities = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.Resolve("Signum.Entities");
            this.SemiSymbolEntity = SigumEntities.MainModule.GetType("Signum.Entities", "Symbol");
        }
Пример #4
0
        public SymbolFixer(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;
            this.Log      = log;

            this.SigumEntities    = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.Resolve("Signum.Entities");
            this.SemiSymbolEntity = SigumEntities.MainModule.GetType("Signum.Entities", "Symbol");
        }
Пример #5
0
        public AutoPropertyConverter(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;

            this.SigumEntities    = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.SignumEntities;
            this.ModifiableEntity = SigumEntities.MainModule.GetType("Signum.Entities", "ModifiableEntity");
            this.SetMethod        = Assembly.MainModule.ImportReference(this.ModifiableEntity.Methods.Single(m => m.Name == "Set" && m.IsDefinition));
            this.GetMethod        = Assembly.MainModule.ImportReference(this.ModifiableEntity.Methods.Single(m => m.Name == "Get" && m.IsDefinition));
        }
Пример #6
0
        public AutoPropertyConverter(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;

            this.SigumEntities = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.SignumEntities;
            this.ModifiableEntity = SigumEntities.MainModule.GetType("Signum.Entities", "ModifiableEntity");
            this.SetMethod = Assembly.MainModule.ImportReference(this.ModifiableEntity.Methods.Single(m => m.Name == "Set" && m.IsDefinition));
            this.GetMethod = Assembly.MainModule.ImportReference(this.ModifiableEntity.Methods.Single(m => m.Name == "Get" && m.IsDefinition));
        }
Пример #7
0
        public FieldAutoInitializer(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;
            this.Log      = log;

            this.SystemType        = resolver.Resolve("mscorlib").MainModule.GetType("System", "Type");
            this.GetTypeFromHandle = this.SystemType.GetMethods().Single(a => a.Name == "GetTypeFromHandle");

            this.SigumEntities            = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.SignumEntities;
            this.AutoInit                 = SigumEntities.MainModule.GetType("Signum.Entities", "AutoInitAttribute");
            this.OperationSymbol          = SigumEntities.MainModule.GetType("Signum.Entities", "OperationSymbol").Resolve();
            this.OperationSymbolConstruct = this.OperationSymbol.NestedTypes.Single(t => t.Name == "Construct`1").Resolve();
        }
Пример #8
0
        public override bool Execute()
        {
            Log.LogMessage("Signum.MSBuildTask starting: {0}", Assembly);
            try
            {
                var  resolver = new PreloadingAssemblyResolver(References);
                bool hasPdb   = File.Exists(Path.ChangeExtension(Assembly, ".pdb"));

                AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters
                {
                    AssemblyResolver     = resolver,
                    ReadingMode          = ReadingMode.Deferred,
                    ReadSymbols          = hasPdb,
                    InMemory             = true,
                    SymbolReaderProvider = hasPdb ? new PdbReaderProvider() : null
                });

                if (AlreadyProcessed(assembly))
                {
                    Log.LogMessage("Signum.MSBuildTask already processed: {0}", Assembly);
                    return(true);
                }

                new AutoPropertyConverter(assembly, resolver).FixProperties();
                new FieldAutoInitializer(assembly, resolver, Log).FixAutoInitializer();
                new AutoExpressionField(assembly, resolver, Log).FixAutoExpressionField();

                if (Log.HasLoggedErrors)
                {
                    return(true);
                }

                MarkAsProcessed(assembly, resolver);

                assembly.Write(Assembly, new WriterParameters
                {
                    WriteSymbols         = hasPdb,
                    SymbolWriterProvider = hasPdb ? new PdbWriterProvider() : null,
                    StrongNameKeyPair    = KeyFile == null ? null : new StrongNameKeyPair(File.ReadAllBytes(KeyFile))
                });

                return(true);
            }
            catch (Exception e)
            {
                Log.LogError("Exception in Signum.MSBuildTask: {0}", e.Message);
                return(false);
            }
        }
Пример #9
0
        public FieldAutoInitializer(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TaskLoggingHelper log)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;
            this.Log = log;

            this.SystemType = resolver.Resolve("mscorlib").MainModule.GetType("System", "Type");
            this.GetTypeFromHandle = this.SystemType.GetMethods().Single(a => a.Name == "GetTypeFromHandle");

            this.SigumEntities = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.SignumEntities;
            this.AutoInit = SigumEntities.MainModule.GetType("Signum.Entities", "AutoInitAttribute");
            this.OperationSymbol = SigumEntities.MainModule.GetType("Signum.Entities", "OperationSymbol").Resolve();
            this.OperationSymbolConstruct = this.OperationSymbol.NestedTypes.Single(t => t.Name == "Construct`1").Resolve();

        }
Пример #10
0
        static void MarkAsProcessed(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver)
        {
            TypeDefinition   generatedCodeAttribute = resolver.SystemRuntime.MainModule.GetType(typeof(GeneratedCodeAttribute).FullName);
            MethodDefinition constructor            = generatedCodeAttribute.Methods.Single(a => a.IsConstructor && a.Parameters.Count == 2);

            TypeReference stringType = assembly.MainModule.TypeSystem.String;

            assembly.CustomAttributes.Add(new CustomAttribute(assembly.MainModule.ImportReference(constructor))
            {
                ConstructorArguments =
                {
                    new CustomAttributeArgument(stringType, "SignumTask"),
                    new CustomAttributeArgument(stringType, typeof(Program).Assembly.GetName().Version.ToString()),
                }
            });
        }
Пример #11
0
        public override bool Execute()
        {
            Log.LogMessage("Signum.MSBuildTask starting: {0}", Assembly);
            try
            {
                var resolver = new PreloadingAssemblyResolver(References);
                bool hasPdb = File.Exists(Path.ChangeExtension(Assembly, ".pdb"));

                AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters
                {
                    AssemblyResolver = resolver,
                    ReadingMode = ReadingMode.Deferred,
                    ReadSymbols = hasPdb,
                    SymbolReaderProvider = hasPdb ? new PdbReaderProvider() : null
                });

                if (AlreadyProcessed(assembly))
                {
                    Log.LogMessage("Signum.MSBuildTask already processed: {0}", Assembly);
                    return true;
                }

                new AutoPropertyConverter(assembly, resolver).FixProperties();
                new FieldAutoInitializer(assembly, resolver, Log).FixAutoInitializer();
                new AutoExpressionField(assembly, resolver, Log).FixAutoExpressionField();

                if (Log.HasLoggedErrors)
                    return true;

                MarkAsProcessed(assembly, resolver);

                assembly.Write(Assembly, new WriterParameters
                {
                    WriteSymbols = hasPdb,
                    SymbolWriterProvider = hasPdb ? new PdbWriterProvider() : null,
                    StrongNameKeyPair = KeyFile == null ? null : new StrongNameKeyPair(File.ReadAllBytes(KeyFile))
                });
                
                return true;
            }
            catch (Exception e)
            {
                Log.LogError("Exception in Signum.MSBuildTask: {0}", e.Message);
                return false;
            }
        }
Пример #12
0
        public FieldAutoInitializer(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TextWriter log)
        {
            this.Assembly = assembly;
            this.Resolver = resolver;
            this.Log      = log;

            var module = resolver.Resolve(AssemblyNameReference.Parse("System.Runtime")).MainModule;

            var tr = module.ExportedTypes.Single(a => a.FullName == "System.Type");

            this.SystemType        = tr.Resolve();
            this.GetTypeFromHandle = this.SystemType.GetMethods().Single(a => a.Name == "GetTypeFromHandle");

            this.SigumEntities            = assembly.Name.Name == "Signum.Entities" ? assembly : resolver.SignumEntities;
            this.AutoInit                 = SigumEntities.MainModule.GetType("Signum.Entities", "AutoInitAttribute");
            this.OperationSymbol          = SigumEntities.MainModule.GetType("Signum.Entities", "OperationSymbol").Resolve();
            this.OperationSymbolConstruct = this.OperationSymbol.NestedTypes.Single(t => t.Name == "Construct`1").Resolve();
        }
Пример #13
0
        public ExpressionFieldGenerator(AssemblyDefinition assembly, PreloadingAssemblyResolver resolver, TextWriter log)
        {
            this.Assembly             = assembly;
            this.Resolver             = resolver;
            this.Log                  = log;
            this.SystemRuntime        = resolver.SystemRuntime;
            this.SignumUtilities      = assembly.Name.Name == "Signum.Utilities" ? assembly : resolver.SignumUtilities;
            this.ExpressionField      = SignumUtilities.MainModule.GetType("Signum.Utilities", "ExpressionFieldAttribute");
            this.AutoExpressionField  = SignumUtilities.MainModule.GetType("Signum.Utilities", "AutoExpressionFieldAttribute");
            this.ExpressionExtensions = SignumUtilities.MainModule.GetType("Signum.Utilities", "ExpressionExtensions");

            this.Type_GetTypeFromHandle = this.SystemRuntime.MainModule.GetType("System", "Type").Methods.Single(a => a.Name == "GetTypeFromHandle");
            var expressionType = resolver.SystemLinqExpressions.MainModule.GetType("System.Linq.Expressions", nameof(System.Linq.Expressions.Expression));

            this.Expression_Parameter = expressionType.Methods.Single(a => a.Name == nameof(Expression.Parameter) && a.Parameters.Count == 2);
            this.Expression_Lambda    = expressionType.Methods.Single(a => a.Name == nameof(Expression.Lambda) && a.GenericParameters.Count == 1 && a.Parameters.Count == 2 && a.Parameters[1].ParameterType.IsArray);
            this.ParameterExpression  = resolver.SystemLinqExpressions.MainModule.GetType("System.Linq.Expressions", nameof(System.Linq.Expressions.ParameterExpression));
            this.Array_Empty          = resolver.SystemRuntime.MainModule.GetType("System", "Array").Methods.Single(a => a.Name == "Empty");
        }
Пример #14
0
        public static int Main(string[] args)
        {
            //if (args.Length != 2)
            //{
            //    Console.WriteLine("Two arguments are needed: IntermediateAssemblyPath and OutputPath");
            //    Console.WriteLine(@"Example: dotnet "..\Signum.MSBuildTask\Binaries\netcoreapp2.1\Signum.MSBuildTask.dll" "@(IntermediateAssembly)" "$(OutputPath)"");
            //    return -1;
            //}

            string intermediateAssembly = args[0];
            string referencesFile       = args[1];

            string[] references = File.ReadAllLines(referencesFile);

            var log = Console.Out;

            if (!File.Exists(intermediateAssembly))
            {
                log.WriteLine("Signum.MSBuildTask skipped (File not found): {0}", intermediateAssembly);
                return(0);
            }

            log.WriteLine("Signum.MSBuildTask starting: {0}", intermediateAssembly);
            try
            {
                var  resolver = new PreloadingAssemblyResolver(references);
                bool hasPdb   = File.Exists(Path.ChangeExtension(intermediateAssembly, ".pdb"));

                AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(intermediateAssembly, new ReaderParameters
                {
                    AssemblyResolver     = resolver,
                    ReadingMode          = ReadingMode.Deferred,
                    ReadSymbols          = hasPdb,
                    InMemory             = true,
                    SymbolReaderProvider = hasPdb ? new PdbReaderProvider() : null
                });

                if (AlreadyProcessed(assembly))
                {
                    log.WriteLine("Signum.MSBuildTask already processed: {0}", intermediateAssembly);
                    return(0);
                }

                bool errors = false;
                errors |= new ExpressionFieldGenerator(assembly, resolver, log).FixAutoExpressionField();
                errors |= new FieldAutoInitializer(assembly, resolver, log).FixAutoInitializer();
                errors |= new AutoPropertyConverter(assembly, resolver).FixProperties();

                if (errors)
                {
                    return(-1);
                }

                MarkAsProcessed(assembly, resolver);

                assembly.Write(intermediateAssembly, new WriterParameters
                {
                    WriteSymbols         = hasPdb,
                    SymbolWriterProvider = hasPdb ? new PdbWriterProvider() : null
                });

                log.WriteLine("Signum.MSBuildTask finished: {0}", intermediateAssembly);

                return(0);
            }
            catch (Exception e)
            {
                log.Write("Exception in Signum.MSBuildTask: {0}", e.Message);
                log.WriteLine(e.StackTrace);
                log.WriteLine(args[1]);
                return(-1);
            }
        }