private static IDictionary<SyntaxNode, SyntaxNode> GetRetroMethods(Compilation compilation, INamedTypeSymbol objectType) { var syntaxNodes = new Dictionary<SyntaxNode, SyntaxNode>(); // FIND // 1. Generic properties symbols // ============================= // NOTE - var genericPropertiesList = new List<IPropertySymbol>(); var genericMethodsList = new List<IMethodSymbol>(); var semanticModels = compilation.SyntaxTrees.Select(x => compilation.GetSemanticModel(x)); foreach (var semanticModel in semanticModels) { var tree = semanticModel.SyntaxTree; // Find generic classes var genericClassFinder = new GenericClassFinder(tree, semanticModel); var classDeclarations = genericClassFinder.Get().ToArray(); SyntaxNode newTree = tree.GetRoot(); // Find reference to it's members // methods symbols var methodsToCast = classDeclarations .SelectMany(x => x.Members) .OfType<BaseMethodDeclarationSyntax>() .Select(x => (IMethodSymbol)semanticModel.GetDeclaredSymbol(x)); genericMethodsList.AddRange(methodsToCast); // properties symbols var propertiesToCast = classDeclarations .SelectMany(x => x.Members) .OfType<BasePropertyDeclarationSyntax>() .Select(x => (IPropertySymbol)semanticModel.GetDeclaredSymbol(x)); genericPropertiesList.AddRange(propertiesToCast); } var genRefs = new GenRef(genericMethodsList, genericPropertiesList); //CHANGE //1. Generic properties references with cast //2. Generic properties to Object properties //====== foreach (var semanticModel in semanticModels) { var root = semanticModel.SyntaxTree.GetRoot(); // get cast changes var castReferences = new Dictionary<SyntaxNode, SyntaxNode>(); CastResursiveMethod(root, semanticModel, genRefs, castReferences); // get generic properties to object properties var retroProperties = GenericToObject(root, semanticModel, objectType); var allChanges = castReferences.Concat(retroProperties); foreach (var ch in allChanges) syntaxNodes.Add(ch.Key, ch.Value); } return syntaxNodes; }
private static IDictionary <SyntaxNode, SyntaxNode> GetRetroMethods(Compilation compilation, INamedTypeSymbol objectType) { var syntaxNodes = new Dictionary <SyntaxNode, SyntaxNode>(); // FIND // 1. Generic properties symbols // ============================= // NOTE - var genericPropertiesList = new List <IPropertySymbol>(); var genericMethodsList = new List <IMethodSymbol>(); var semanticModels = compilation.SyntaxTrees.Select(x => compilation.GetSemanticModel(x)); foreach (var semanticModel in semanticModels) { var tree = semanticModel.SyntaxTree; // Find generic classes var genericClassFinder = new GenericClassFinder(tree, semanticModel); var classDeclarations = genericClassFinder.Get().ToArray(); SyntaxNode newTree = tree.GetRoot(); // Find reference to it's members // methods symbols var methodsToCast = classDeclarations .SelectMany(x => x.Members) .OfType <BaseMethodDeclarationSyntax>() .Select(x => (IMethodSymbol)semanticModel.GetDeclaredSymbol(x)); genericMethodsList.AddRange(methodsToCast); // properties symbols var propertiesToCast = classDeclarations .SelectMany(x => x.Members) .OfType <BasePropertyDeclarationSyntax>() .Select(x => (IPropertySymbol)semanticModel.GetDeclaredSymbol(x)); genericPropertiesList.AddRange(propertiesToCast); } var genRefs = new GenRef(genericMethodsList, genericPropertiesList); //CHANGE //1. Generic properties references with cast //2. Generic properties to Object properties //====== foreach (var semanticModel in semanticModels) { var root = semanticModel.SyntaxTree.GetRoot(); // get cast changes var castReferences = new Dictionary <SyntaxNode, SyntaxNode>(); CastResursiveMethod(root, semanticModel, genRefs, castReferences); // get generic properties to object properties var retroProperties = GenericToObject(root, semanticModel, objectType); var allChanges = castReferences.Concat(retroProperties); foreach (var ch in allChanges) { syntaxNodes.Add(ch.Key, ch.Value); } } return(syntaxNodes); }