private static void Execute(ModuleDefinition mainModule, ModuleDefinition l2MModule, ModuleDefinition coreModule)
        {
            var l2MOptimizeAttribute = l2MModule.GetType("LinqPatcher.Attributes", "OptimizeAttribute");
            var typeSystem           = mainModule.TypeSystem;

            var classAnalyzer  = new ClassAnalyzer(mainModule, l2MOptimizeAttribute);
            var methodAnalyzer = new MethodAnalyzer(typeSystem);
            var methodBuilder  = new MethodBuilder(mainModule, coreModule);

            var analyzedClass = classAnalyzer.Analyze();

            foreach (var targetClass in analyzedClass.OptimizeTypes)
            {
                foreach (var method in classAnalyzer.AnalyzeMethod(targetClass))
                {
                    var analyzedMethod = methodAnalyzer.Analyze(method);
                    var methodName     = Guid.NewGuid().ToString("N");

                    methodBuilder.Create(targetClass, methodName, analyzedMethod.ParameterType, analyzedMethod.ReturnType);
                    methodBuilder.Begin();

                    foreach (var linqOperator in analyzedMethod.Operators)
                    {
                        var linq = methodAnalyzer.OperatorFactory(linqOperator, methodBuilder);
                        methodBuilder.AppendOperator(linq);
                    }

                    methodBuilder.BuildOperator();
                    methodBuilder.End();
                    methodBuilder.Replace(method);
                }
            }

            mainModule.Write("Main.dll");
        }
Ejemplo n.º 2
0
        private static void Execute(ModuleDefinition mainModule, ModuleDefinition l2MModule, ModuleDefinition coreModule)
        {
            var l2MOptimizeAttribute = l2MModule.GetType("LinqPatcher.Attributes", "OptimizeAttribute");

            var classAnalyzer  = new ClassAnalyzer(mainModule, l2MOptimizeAttribute);
            var methodAnalyzer = new MethodAnalyzer(coreModule);
            var methodBuilder  = new MethodBuilder(mainModule, coreModule);

            var analyzedClass = classAnalyzer.Analyze();

            foreach (var optimizeClass in analyzedClass.OptimizeTypes)
            {
                foreach (var method in classAnalyzer.AnalyzeMethod(optimizeClass))
                {
                    var analyzedMethod = methodAnalyzer.Analyze(method);

                    var returnType = mainModule.ImportReference(analyzedMethod.ReturnType);

                    methodBuilder.Create(optimizeClass, MethodHelper.CreateUniqueName, analyzedMethod.ParameterType, returnType);
                    methodBuilder.Begin();

                    foreach (var linqOperator in analyzedMethod.Operators)
                    {
                        var linq = methodAnalyzer.OperatorFactory(linqOperator, methodBuilder);
                        methodBuilder.AppendOperator(linq);
                    }

                    methodBuilder.BuildOperator();
                    methodBuilder.End();
                    methodBuilder.Replace(method);
                }
            }

            mainModule.Write($"{TargetModuleName}.dll");
        }