private (ClassReader, CodeModelBuilder) GetClassReaderFromCode( string csharpCode, string className, Func <INamedTypeSymbol, INamedTypeSymbol> walkSymbols = null, Action <List <IPhasedTypeReader> > setupAllReaders = null) { var compilation = TestWorkspaceFactory.CompileCodeOrThrow( csharpCode, references: new[] { this.GetType().Assembly.Location }); var originSymbol = compilation.GetTypeByMetadataName(className); var typeSymbol = walkSymbols?.Invoke(originSymbol) ?? originSymbol; typeSymbol.ShouldNotBeNull($"Type symbol '{className}' could not be found in compilation."); var modelBuilder = new CodeModelBuilder(compilation); var allReaders = new List <IPhasedTypeReader>(); var discoveryVisitor = new TypeDiscoverySymbolVisitor(modelBuilder, allReaders); var readerContext = new CodeReaderContext(modelBuilder.GetCodeModel(), null, LanguageInfo.Entries.CSharp()); compilation.GlobalNamespace.Accept(discoveryVisitor); setupAllReaders?.Invoke(allReaders); var reader = allReaders.OfType <ClassReader>().FirstOrDefault(r => r.TypeSymbol.Equals(typeSymbol)); reader.ShouldNotBeNull($"ClassReader for '{className}' was not registered."); allReaders.ForEach(r => r.RegisterProxy()); return(reader, modelBuilder); }
public static MethodSignature ReadSignature(CodeModelBuilder modelBuilder, IMethodSymbol symbol) { return(ReadSignature(modelBuilder.GetCodeModel(), symbol)); }