private static INamespaceOrTypeSymbol CreateCodeGenerationSymbol( Document document, ISymbol symbol ) { symbol = symbol.GetOriginalUnreducedDefinition(); var topLevelNamespaceSymbol = symbol.ContainingNamespace; var topLevelNamedType = MetadataAsSourceHelpers.GetTopLevelContainingNamedType(symbol); var canImplementImplicitly = document.GetLanguageService <ISemanticFactsService>().SupportsImplicitInterfaceImplementation; var docCommentFormattingService = document.GetLanguageService <IDocumentationCommentFormattingService>(); INamespaceOrTypeSymbol wrappedType = new WrappedNamedTypeSymbol( topLevelNamedType, canImplementImplicitly, docCommentFormattingService ); return(topLevelNamespaceSymbol.IsGlobalNamespace ? wrappedType : CodeGenerationSymbolFactory.CreateNamespaceSymbol( topLevelNamespaceSymbol.ToDisplayString(SymbolDisplayFormats.NameFormat), null, new[] { wrappedType } )); }
protected SyntaxNode CreateNamespaceDeclaration(SyntaxNode containerNode, string name) { var destination = CodeModelService.GetDestination(containerNode); var newNamespaceSymbol = CodeGenerationSymbolFactory.CreateNamespaceSymbol(name); var newNamespace = CodeGenerationService.CreateNamespaceDeclaration( newNamespaceSymbol, destination); return(newNamespace); }
public static INamespaceOrTypeSymbol GenerateRootNamespaceOrType(this INamedTypeSymbol namedType, string[] containers) { INamespaceOrTypeSymbol currentSymbol = namedType; for (int i = containers.Length - 1; i >= 0; i--) { currentSymbol = CodeGenerationSymbolFactory.CreateNamespaceSymbol(containers[i], members: new[] { currentSymbol }); } return(currentSymbol); }
public async Task TestThrowsOnGenerateNamespace() { var namespaceSymbol = CodeGenerationSymbolFactory.CreateNamespaceSymbol("Outerspace"); using (var context = TestContext.Create()) { await Assert.ThrowsAsync <ArgumentException>(async() => { await context.GenerateSourceAsync(namespaceSymbol); }); } }
internal static async Task TestAddNamespaceAsync( string initial, string expected, string name = "N", IList<ISymbol> imports = null, IList<INamespaceOrTypeSymbol> members = null, CodeGenerationOptions codeGenerationOptions = null) { using var context = await TestContext.CreateAsync(initial, expected); var @namespace = CodeGenerationSymbolFactory.CreateNamespaceSymbol(name, imports, members); context.Result = await context.Service.AddNamespaceAsync(context.Solution, (INamespaceSymbol)context.GetDestination(), @namespace, codeGenerationOptions); }
internal static async Task TestAddNamespaceAsync( string initial, string expected, string name = "N", IList <ISymbol> imports = null, IList <INamespaceOrTypeSymbol> members = null, CodeGenerationContext context = null) { using var testContext = await TestContext.CreateAsync(initial, expected); var @namespace = CodeGenerationSymbolFactory.CreateNamespaceSymbol(name, imports, members); testContext.Result = await testContext.Service.AddNamespaceAsync(testContext.Solution, (INamespaceSymbol)testContext.GetDestination(), @namespace, context ?? CodeGenerationContext.Default, CancellationToken.None); }
internal static void TestAddNamespace( string initial, string expected, string name = "N", IList <ISymbol> imports = null, IList <INamespaceOrTypeSymbol> members = null, CodeGenerationOptions codeGenerationOptions = default(CodeGenerationOptions), bool compareTokens = true) { using (var context = new TestContext(initial, expected, compareTokens)) { var @namespace = CodeGenerationSymbolFactory.CreateNamespaceSymbol(name, imports, members); context.Result = context.Service.AddNamespaceAsync(context.Solution, (INamespaceSymbol)context.GetDestination(), @namespace, codeGenerationOptions).Result; } }
public void TestThrowsOnGenerateNamespace() { var namespaceSymbol = CodeGenerationSymbolFactory.CreateNamespaceSymbol("Outerspace"); using (var context = new TestContext()) { Assert.Throws <ArgumentException>(() => { try { context.GenerateSource(namespaceSymbol); } catch (AggregateException ae) { throw ae.InnerException; } }); } }