public async Task ImmediatelyDerivedTypes_CrossLanguage() { var solution = new AdhocWorkspace().CurrentSolution; // create portable assembly with an abstract base class solution = AddProjectWithMetadataReferences(solution, "PortableProject", LanguageNames.CSharp, @" namespace N { public abstract class BaseClass { } } ", MscorlibRefPortable); // create a normal assembly with a type derived from the portable abstract base solution = AddProjectWithMetadataReferences(solution, "NormalProject", LanguageNames.VisualBasic, @" Imports N Namespace M Public Class DerivedClass Inherits BaseClass End Class End Namespace ", MscorlibRef, solution.Projects.Single(pid => pid.Name == "PortableProject").Id); // get symbols for types var portableCompilation = await solution.Projects.Single(p => p.Name == "PortableProject").GetCompilationAsync(); var baseClassSymbol = portableCompilation.GetTypeByMetadataName("N.BaseClass"); var normalCompilation = await solution.Projects.Single(p => p.Name == "NormalProject").GetCompilationAsync(); var derivedClassSymbol = normalCompilation.GetTypeByMetadataName("M.DerivedClass"); // verify that the symbols are different (due to retargeting) Assert.NotEqual(baseClassSymbol, derivedClassSymbol.BaseType); // verify that the dependent types of `N.BaseClass` correctly resolve to `M.DerivedCLass` var derivedFromBase = await DependentTypeFinder.GetTypesImmediatelyDerivedFromClassesAsync(baseClassSymbol, solution, CancellationToken.None); var derivedDependentType = derivedFromBase.Single(); Assert.Equal(derivedClassSymbol, derivedDependentType); }
public async Task <GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken) { var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false); foreach (var node in context.InputNodes) { var namedType = graphBuilder.GetSymbol(node) as INamedTypeSymbol; if (namedType == null) { continue; } if (namedType.TypeKind == TypeKind.Class) { var derivedTypes = await DependentTypeFinder.GetTypesImmediatelyDerivedFromClassesAsync(namedType, solution, cancellationToken).ConfigureAwait(false); foreach (var derivedType in derivedTypes) { var symbolNode = await graphBuilder.AddNodeForSymbolAsync(derivedType, relatedNode : node).ConfigureAwait(false); graphBuilder.AddLink(symbolNode, CodeLinkCategories.InheritsFrom, node); } } else if (namedType.TypeKind == TypeKind.Interface) { var derivedTypes = await DependentTypeFinder.GetTypesImmediatelyDerivedFromInterfacesAsync(namedType, solution, cancellationToken).ConfigureAwait(false); foreach (var derivedType in derivedTypes) { var symbolNode = await graphBuilder.AddNodeForSymbolAsync(derivedType, relatedNode : node).ConfigureAwait(false); graphBuilder.AddLink(symbolNode, CodeLinkCategories.InheritsFrom, node); } } } return(graphBuilder); }