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"); }
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"); }
public string Generate(string classAsAString) { var analyzer = new ClassAnalyzer(); var analysisResult = analyzer.Analyze(classAsAString); var modelCreator = new BuilderModelCreator(); var model = modelCreator.Create(analysisResult); var codeGenerator = new BuilderCodeGenerator(); return(codeGenerator.Generate(model)); }
public void ResultShouldContainClassTreeReferenceAndNamespace() { var syntaxTree = roslynFixture.CreateSyntaxTree("class MyClass {}"); var classTree = roslynFixture.FindFirstClassDeclaration(syntaxTree); var @namespace = "MyNamespace"; var analyzedClass = classAnalyzer.Analyze(@namespace, classTree); Assert.AreSame(classTree, analyzedClass.ClassTree); Assert.AreEqual(@namespace, analyzedClass.Namespace); }
private AnalysisResult Execute() { var analyzer = new ClassAnalyzer(); return(analyzer.Analyze(classAsAString)); }