public async Task <MethodDescriptor> FindMethodImplementationAsync(MethodDescriptor methodDescriptor, TypeDescriptor typeDescriptor) { //var roslynMethod = RoslynSymbolFactory.FindMethodInCompilation(methodDescriptor, this.Compilation); var methodParserInfo = await this.FindMethodInProjectAsync(methodDescriptor); //if (roslynMethod != null) if (methodParserInfo != null) { var roslynMethod = methodParserInfo.MethodSymbol; var roslynType = RoslynSymbolFactory.GetTypeByName(typeDescriptor, this.Compilation); var implementedMethod = Utils.FindMethodImplementation(roslynMethod, roslynType); //Contract.Assert(implementedMethod != null); if (implementedMethod != null) { methodDescriptor = Utils.CreateMethodDescriptor(implementedMethod); } } else { // If it is interface/abstract or code that we did not parse (library) var roslynMethod = RoslynSymbolFactory.FindMethodInCompilation(methodDescriptor, this.Compilation); if (roslynMethod != null) { var roslynType = RoslynSymbolFactory.GetTypeByName(typeDescriptor, this.Compilation); var implementedMethod = Utils.FindMethodImplementation(roslynMethod, roslynType); if (implementedMethod != null) { methodDescriptor = Utils.CreateMethodDescriptor(implementedMethod); } } } // TODO: If we cannot resolve the method, we return the same method. // Maybe we should consider to return null instead? return(methodDescriptor); }
public virtual async Task <bool> IsSubtypeAsync(TypeDescriptor typeDescriptor1, TypeDescriptor typeDescriptor2) { var result = false; if (typeDescriptor1.Equals(typeDescriptor2)) { result = true; } else { var roslynType1 = RoslynSymbolFactory.GetTypeByName(typeDescriptor1, this.Compilation); if (roslynType1 == null && typeDescriptor1.AssemblyName != this.Project.AssemblyName) { // We assume if T1 <= T2, then the project (compilation) where T1 is declared must know T2 also var projectProvider = await this.solutionManager.GetProjectCodeProviderAsync(typeDescriptor1.AssemblyName); result = await projectProvider.IsSubtypeAsync(typeDescriptor1, typeDescriptor2); } else { var roslynType2 = RoslynSymbolFactory.GetTypeByName(typeDescriptor2, this.Compilation); if (roslynType2 == null) { // We assume if this project (compilation) knows T1 but don't know T2, // then it cannot be T1 <= T2 result = false; } else { result = TypeHelper.InheritsByName(roslynType1, roslynType2); } } } return(result); }
public Task <MethodDescriptor> FindMethodImplementationUsingRoslynAsync(MethodDescriptor methodDescriptor, TypeDescriptor typeDescriptor) { var roslynMethod = RoslynSymbolFactory.FindMethodInCompilation(methodDescriptor, this.Compilation); if (roslynMethod != null) { var roslynType = RoslynSymbolFactory.GetTypeByName(typeDescriptor, this.Compilation); var implementedMethod = Utils.FindMethodImplementation(roslynMethod, roslynType); //Contract.Assert(implementedMethod != null); if (implementedMethod != null) { methodDescriptor = Utils.CreateMethodDescriptor(implementedMethod); } else { Logger.LogS("BaseProjectCodeProvider", "FindMethodImplementationAsync", "Cannot find implementation for method {0}", methodDescriptor); } } // If we cannot resolve the method, we return the same method. return(Task.FromResult(methodDescriptor)); }