474 references to UsingDirectiveSyntax
Microsoft.CodeAnalysis.CSharp (57)
Binder\AliasAndUsingDirective.cs (3)
15public AliasAndUsingDirective(AliasSymbol alias, UsingDirectiveSyntax? usingDirective) 21public UsingDirectiveSyntax? UsingDirective => (UsingDirectiveSyntax?)UsingDirectiveReference?.GetSyntax();
Binder\Binder_Symbols.cs (3)
487if (refTypeSyntax.Parent is UsingDirectiveSyntax) 945if (node.Parent is UsingDirectiveSyntax { Alias: not null }) 1004case UsingDirectiveSyntax usingDirective:
Binder\ImportChain.cs (1)
106var syntax = aliasAndUsingDirective.UsingDirective;
Binder\NamespaceOrTypeAndUsingDirective.cs (3)
17public NamespaceOrTypeAndUsingDirective(NamespaceOrTypeSymbol namespaceOrType, UsingDirectiveSyntax? usingDirective, ImmutableArray<AssemblySymbol> dependencies) 24public UsingDirectiveSyntax? UsingDirective => (UsingDirectiveSyntax?)UsingDirectiveReference?.GetSyntax();
Binder\WithExternAndUsingAliasesBinder.cs (1)
173SyntaxList<UsingDirectiveSyntax> usingDirectives;
Compilation\CSharpCompilation.cs (2)
2763internal void RecordImport(UsingDirectiveSyntax syntax) 2780internal void RecordImportDependencies(UsingDirectiveSyntax syntax, ImmutableArray<AssemblySymbol> dependencies)
Compilation\CSharpSemanticModel.cs (3)
3197public abstract IAliasSymbol GetDeclaredSymbol(UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken)); 5124var usingDirective = (UsingDirectiveSyntax)node;
Compilation\MemberSemanticModel.cs (1)
802public override IAliasSymbol GetDeclaredSymbol(UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
Compilation\SpeculativeSemanticModelWithMemberModel.cs (1)
355public override IAliasSymbol GetDeclaredSymbol(UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
Compilation\SyntaxTreeSemanticModel.cs (1)
1916UsingDirectiveSyntax declarationSyntax,
CSharpExtensions.cs (1)
1544public static IAliasSymbol? GetDeclaredSymbol(this SemanticModel? semanticModel, UsingDirectiveSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
Declarations\DeclarationTreeBuilder.cs (4)
362SyntaxList<UsingDirectiveSyntax> usings, bool global) 366foreach (var directive in usings) 475private static void CheckFeatureAvailabilityForUsings(DiagnosticBag diagnostics, SyntaxList<UsingDirectiveSyntax> usings) 477foreach (var usingDirective in usings)
Parser\LanguageParser.cs (6)
148public SyntaxListBuilder<UsingDirectiveSyntax> Usings; 155Usings = pool.Allocate<UsingDirectiveSyntax>(); 175new SyntaxList<UsingDirectiveSyntax>(), 826var @using = this.ParseUsingDirective(); 950private UsingDirectiveSyntax ParseUsingDirective() 954return (UsingDirectiveSyntax)this.EatNode();
SymbolDisplay\SymbolDisplayVisitor_Minimal.cs (1)
202if (startNode is UsingDirectiveSyntax)
Symbols\AliasSymbol.cs (4)
132: GetDeclaringSyntaxReferenceHelper<UsingDirectiveSyntax>(_locations); 285internal AliasSymbolFromSyntax(SourceNamespaceSymbol containingSymbol, UsingDirectiveSyntax syntax) 322: ResolveAliasTarget((UsingDirectiveSyntax)_directive.GetSyntax(), newDiagnostics, basesBeingResolved); 371UsingDirectiveSyntax usingDirective,
Symbols\Source\QuickAttributeChecker.cs (2)
85internal QuickAttributeChecker AddAliasesIfAny(SyntaxList<UsingDirectiveSyntax> usingsSyntax, bool onlyGlobalAliases = false) 94foreach (var usingDirective in usingsSyntax)
Symbols\Source\SourceNamespaceSymbol.AliasesAndUsings.cs (5)
554SyntaxList<UsingDirectiveSyntax> usingDirectives; 616SyntaxList<UsingDirectiveSyntax> usingDirectives, 651foreach (var usingDirective in usingDirectives) 1016UsingDirectiveSyntax usingDirective = @using.UsingDirective!; 1066void recordImportDependencies(UsingDirectiveSyntax usingDirective, NamespaceOrTypeSymbol target)
Syntax\NamespaceDeclarationSyntax.cs (1)
21public NamespaceDeclarationSyntax Update(SyntaxToken namespaceKeyword, NameSyntax name, SyntaxToken openBraceToken, SyntaxList<ExternAliasDirectiveSyntax> externs, SyntaxList<UsingDirectiveSyntax> usings, SyntaxList<MemberDeclarationSyntax> members, SyntaxToken closeBraceToken, SyntaxToken semicolonToken)
Syntax\SyntaxFactory.cs (4)
2658public static UsingDirectiveSyntax UsingDirective(NameEqualsSyntax alias, NameSyntax name) 2668public static UsingDirectiveSyntax UsingDirective(SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken) 2700public static NamespaceDeclarationSyntax NamespaceDeclaration(NameSyntax name, SyntaxList<ExternAliasDirectiveSyntax> externs, SyntaxList<UsingDirectiveSyntax> usings, SyntaxList<MemberDeclarationSyntax> members) 2704public static NamespaceDeclarationSyntax NamespaceDeclaration(SyntaxToken namespaceKeyword, NameSyntax name, SyntaxToken openBraceToken, SyntaxList<ExternAliasDirectiveSyntax> externs, SyntaxList<UsingDirectiveSyntax> usings, SyntaxList<MemberDeclarationSyntax> members, SyntaxToken closeBraceToken, SyntaxToken semicolonToken)
Syntax\SyntaxFacts.cs (1)
251return ((UsingDirectiveSyntax)parent).NamespaceOrType == node;
Syntax\SyntaxNormalizer.cs (2)
659token.Parent.Parent?.Parent is not UsingDirectiveSyntax) 1376node is UsingDirectiveSyntax ||
Syntax\UsingDirectiveSyntax.cs (7)
12/// Returns the name this <see cref="UsingDirectiveSyntax"/> points at, or <see langword="null"/> if it does not 21public UsingDirectiveSyntax Update(SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken) 24public UsingDirectiveSyntax Update(SyntaxToken globalKeyword, SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken) 27public UsingDirectiveSyntax WithName(NameSyntax name) 37public static UsingDirectiveSyntax UsingDirective(SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name) 41public static UsingDirectiveSyntax UsingDirective(SyntaxToken globalKeyword, SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken) 45public static UsingDirectiveSyntax UsingDirective(NameSyntax name)
Microsoft.CodeAnalysis.CSharp.CodeStyle (41)
src\Analyzers\CSharp\Analyzers\MisplacedUsingDirectives\MisplacedUsingDirectivesDiagnosticAnalyzer.cs (2)
100IEnumerable<UsingDirectiveSyntax> usingDirectives, CodeStyleOption2<AddImportPlacement> option) 102foreach (var usingDirective in usingDirectives)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryImports\CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer.cs (3)
24AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer<UsingDirectiveSyntax> 37protected override ImmutableArray<SyntaxNode> MergeImports(ImmutableArray<UsingDirectiveSyntax> unnecessaryImports) 40protected override IUnnecessaryImportsProvider<UsingDirectiveSyntax> UnnecessaryImportsProvider
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SemanticModelExtensions.cs (1)
166foreach (var @using in location.GetEnclosingUsingDirectives())
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (2)
306public static IEnumerable<UsingDirectiveSyntax> GetEnclosingUsingDirectives(this SyntaxNode node) 372var usingDirectiveAncestor = contextNode.GetAncestor<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\AnchorIndentationFormattingRule.cs (1)
54case UsingDirectiveSyntax usingNode:
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\ElasticTriviaFormattingRule.cs (2)
462else if (previousToken.Parent is UsingDirectiveSyntax) 464return currentToken.Parent is UsingDirectiveSyntax ? 1 : 2;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\TokenBasedFormattingRule.cs (3)
230if (previousToken.Parent is not UsingDirectiveSyntax previousUsing) 237currentToken.Parent is UsingDirectiveSyntax currentUsing && 256private static SyntaxList<UsingDirectiveSyntax> GetUsings(SyntaxNode node)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Helpers\RemoveUnnecessaryImports\CSharpUnnecessaryImportsProvider.cs (4)
15: AbstractUnnecessaryImportsProvider<UsingDirectiveSyntax> 23public override ImmutableArray<UsingDirectiveSyntax> GetUnnecessaryImports( 32using var _ = ArrayBuilder<UsingDirectiveSyntax>.GetInstance(out var result); 36root.FindNode(diagnostic.Location.SourceSpan) is UsingDirectiveSyntax node && predicate(node))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SemanticFacts\CSharpSemanticFacts.cs (2)
145private static void AppendAliasNames(SyntaxList<UsingDirectiveSyntax> usings, ImmutableHashSet<string>.Builder builder) 147foreach (var @using in usings)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (4)
196=> node?.Parent is UsingDirectiveSyntax usingDirective && 200=> node is UsingDirectiveSyntax usingDirectiveNode && usingDirectiveNode.Alias != null; 204var usingDirective = (UsingDirectiveSyntax)node;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\FormattingRangeHelper.cs (1)
120if (parent is UsingDirectiveSyntax or
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\UsingsAndExternAliasesDirectiveComparer.cs (5)
46private static UsingKind GetUsingKind(UsingDirectiveSyntax? usingDirective, ExternAliasDirectiveSyntax? externDirective) 90var using1 = directive1 as UsingDirectiveSyntax; 91var using2 = directive2 as UsingDirectiveSyntax;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\UsingsAndExternAliasesOrganizer.cs (11)
18SyntaxList<UsingDirectiveSyntax> usingList, 23out SyntaxList<UsingDirectiveSyntax> organizedUsingList) 42var firstUsing = organizedUsingList[0]; 53var lastUsing = organizedUsingList[i - 1]; 54var currentUsing = organizedUsingList[i]; 67UsingDirectiveSyntax using1, 68UsingDirectiveSyntax using2) 106SyntaxList<UsingDirectiveSyntax> usingList, 110out SyntaxList<UsingDirectiveSyntax> organizedUsingList) 148.Where(t => t is UsingDirectiveSyntax) 149.Cast<UsingDirectiveSyntax>()];
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (65)
src\Analyzers\CSharp\CodeFixes\MisplacedUsingDirectives\MisplacedUsingDirectivesCodeFixProvider.cs (12)
105private static ImmutableArray<UsingDirectiveSyntax> GetAllUsingDirectives(CompilationUnitSyntax compilationUnit) 107using var _ = ArrayBuilder<UsingDirectiveSyntax>.GetInstance(out var result); 109foreach (var usingDirective in compilationUnit.Usings) 136ImmutableArray<UsingDirectiveSyntax> allUsingDirectives, 169Document document, CompilationUnitSyntax compilationUnit, ImmutableArray<UsingDirectiveSyntax> allUsingDirectives, CancellationToken cancellationToken) 185private static async Task<SyntaxNode> ExpandUsingDirectiveAsync(Document document, UsingDirectiveSyntax usingDirective, CancellationToken cancellationToken) 249private static (BaseNamespaceDeclarationSyntax namespaceWithoutUsings, ImmutableArray<UsingDirectiveSyntax> usingsFromNamespace) RemoveUsingsFromNamespace( 271private static (IEnumerable<UsingDirectiveSyntax> deduplicatedUsings, IEnumerable<SyntaxTrivia> orphanedTrivia) RemoveDuplicateUsings( 272IEnumerable<UsingDirectiveSyntax> existingUsings, 273ImmutableArray<UsingDirectiveSyntax> usingsToAdd) 277var deduplicatedUsingsBuilder = ImmutableArray.CreateBuilder<UsingDirectiveSyntax>(); 280foreach (var usingDirective in usingsToAdd)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\NamespaceGenerator.cs (2)
139private static SyntaxList<UsingDirectiveSyntax> GenerateUsingDirectives(INamespaceSymbol innermostNamespace) 150private static UsingDirectiveSyntax? GenerateUsingDirective(ISymbol symbol)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\BaseNamespaceDeclarationSyntaxExtensions.cs (2)
15IList<UsingDirectiveSyntax> usingDirectives, 22var newUsings = new List<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\CompilationUnitSyntaxExtensions.cs (6)
68UsingDirectiveSyntax usingDirective, 78IList<UsingDirectiveSyntax> usingDirectives, 102IList<UsingDirectiveSyntax> usingDirectives, 140private static List<UsingDirectiveSyntax> AddUsingDirectives( 141CompilationUnitSyntax root, IList<UsingDirectiveSyntax> usingDirectives) 144var usings = new List<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\CSharpSyntaxContext.cs (3)
274isInImportsDirective: leftToken.GetAncestor<UsingDirectiveSyntax>() != null, 297isRightAfterUsingOrImportDirective: targetToken.Parent is UsingDirectiveSyntax usingDirective && usingDirective?.GetLastToken() == targetToken, 431var usingDirective = leftToken.GetAncestor<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTokenExtensions.cs (4)
27var usingDirective = token.GetAncestor<UsingDirectiveSyntax>(); 41if (token is { RawKind: (int)SyntaxKind.StaticKeyword, Parent: UsingDirectiveSyntax }) 48token.GetPreviousToken() is { RawKind: (int)SyntaxKind.StaticKeyword, Parent: UsingDirectiveSyntax }) 508targetToken.GetAncestors<UsingDirectiveSyntax>().Any(d => d.UnsafeKeyword.IsKind(SyntaxKind.UnsafeKeyword));
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (4)
419(nextToken.Kind() == SyntaxKind.GlobalKeyword && nextToken.GetAncestor<UsingDirectiveSyntax>()?.GlobalKeyword == nextToken)) 581if (token.GetAncestor<UsingDirectiveSyntax>() is not null) 645var usingDirective = token.GetAncestor<UsingDirectiveSyntax>(); 794token.GetAncestor<UsingDirectiveSyntax>() != null)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ITypeSymbolExtensions.cs (2)
126foreach (var applicableUsing in applicableUsings) 143private static IEnumerable<UsingDirectiveSyntax> GetApplicableUsings(int position, SyntaxNode root)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\UsingDirectiveSyntaxExtensions.cs (2)
15this List<UsingDirectiveSyntax> usingDirectives, 16SyntaxList<UsingDirectiveSyntax> existingDirectives,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpAddImportsService.cs (13)
27CompilationUnitSyntax, BaseNamespaceDeclarationSyntax, UsingDirectiveSyntax, ExternAliasDirectiveSyntax> 39protected override SyntaxNode? GetAlias(UsingDirectiveSyntax usingOrAlias) 42protected override bool IsStaticUsing(UsingDirectiveSyntax usingOrAlias) 47UsingDirectiveSyntax[] usingDirectives, 48UsingDirectiveSyntax[] staticUsingDirectives, 49UsingDirectiveSyntax[] aliasDirectives, 67protected override SyntaxList<UsingDirectiveSyntax> GetUsingsAndAliases(SyntaxNode node) 94private readonly UsingDirectiveSyntax[] _aliasDirectives; 96private readonly UsingDirectiveSyntax[] _usingDirectives; 97private readonly UsingDirectiveSyntax[] _staticUsingDirectives; 101UsingDirectiveSyntax[] usingDirectives, 102UsingDirectiveSyntax[] staticUsingDirectives, 103UsingDirectiveSyntax[] aliasDirectives,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpRemoveUnnecessaryImportsService.cs (2)
27AbstractRemoveUnnecessaryImportsService<UsingDirectiveSyntax> 34protected override IUnnecessaryImportsProvider<UsingDirectiveSyntax> UnnecessaryImportsProvider
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpRemoveUnnecessaryImportsService.Rewriter.cs (13)
25private readonly ISet<UsingDirectiveSyntax> _unnecessaryUsingsDoNotAccessDirectly; 29ISet<UsingDirectiveSyntax> unnecessaryUsings, 44SyntaxList<UsingDirectiveSyntax> usings, 45ISet<UsingDirectiveSyntax> usingsToRemove, 46out SyntaxList<UsingDirectiveSyntax> finalUsings, 49var currentUsings = new List<UsingDirectiveSyntax>(usings); 58var currentUsing = currentUsings[i]; 73var nextUsing = currentUsings[nextIndex]; 114var currentUsing = currentUsings[i]; 129private ISet<UsingDirectiveSyntax> GetUsingsToRemove( 130SyntaxList<UsingDirectiveSyntax> oldUsings, 131SyntaxList<UsingDirectiveSyntax> newUsings) 135var result = new HashSet<UsingDirectiveSyntax>();
Microsoft.CodeAnalysis.CSharp.EditorFeatures (3)
AutomaticCompletion\AutomaticLineEnderCommandHandler.cs (3)
180UsingDirectiveSyntax => SyntaxFactory.ParseCompilationUnit(textToParse, options: (CSharpParseOptions)tree.Options), 217if (owningNode is UsingDirectiveSyntax u && u.NamespaceOrType.IsMissing) 298or UsingDirectiveSyntax
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (2)
SymbolKey\SymbolKeyTestBase.cs (2)
252var usingNodes = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>(); 254foreach (var u in usingNodes)
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (2)
Attributes\AttributeTests.cs (2)
87var nodes = Parse(aliases).GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>(); 88var list = new SyntaxList<UsingDirectiveSyntax>().AddRange(nodes);
Microsoft.CodeAnalysis.CSharp.Features (41)
AddImport\CSharpAddImportFeatureService.cs (5)
40=> node.GetAncestor<UsingDirectiveSyntax>()?.Parent is CompilationUnitSyntax; 396var usingDirective = UsingDirective( 438private static (UsingDirectiveSyntax, bool hasExistingImport) GetUsingDirective( 457var dummyUsing = UsingDirective(nameSyntax); 486var usingDirective = UsingDirective(nameSyntax)
Completion\CompletionProviders\ImportCompletion\ExtensionMethodImportCompletionProvider.cs (1)
45UsingDirectiveSyntax usingDirective => usingDirective.SemicolonToken == token,
Completion\CompletionProviders\ImportCompletion\TypeImportCompletionProvider.cs (2)
23internal sealed class TypeImportCompletionProvider : AbstractTypeImportCompletionProvider<UsingDirectiveSyntax> 45UsingDirectiveSyntax usingDirective => usingDirective.SemicolonToken == token,
Completion\KeywordRecommenders\NamespaceKeywordRecommender.cs (1)
85(nextToken.Kind() == SyntaxKind.GlobalKeyword && nextToken.GetAncestor<UsingDirectiveSyntax>()?.GlobalKeyword == nextToken))
ConvertProgram\ConvertProgramTransform_TopLevelStatements.cs (2)
75using var _ = ArrayBuilder<UsingDirectiveSyntax>.GetInstance(out var directives); 89private static void AddUsingDirectives(NameSyntax name, SyntaxAnnotation annotation, ArrayBuilder<UsingDirectiveSyntax> directives)
Diagnostics\Analyzers\TypeSyntaxSimplifierWalker.cs (3)
107foreach (var usingDirective in compilationUnit.Usings) 118void AddAliasedName(UsingDirectiveSyntax usingDirective) 131foreach (var usingDirective in namespaceDeclaration.Usings)
EditAndContinue\SyntaxComparer.cs (5)
828var leftUsing = (UsingDirectiveSyntax)leftNode; 829var rightUsing = (UsingDirectiveSyntax)rightNode; 1419return ((UsingDirectiveSyntax)node).NamespaceOrType;
FullyQualify\CSharpFullyQualifyService.cs (2)
59simpleName.Parent is UsingDirectiveSyntax { Alias: null, StaticKeyword.RawKind: 0 } usingDirective) 61var newUsingDirective = usingDirective
GenerateType\CSharpGenerateTypeService.cs (2)
134var usingDirectiveSyntax = simpleName.GetAncestorOrThis<UsingDirectiveSyntax>(); 735var usingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(includeUsingsOrImports));
LineSeparators\CSharpLineSeparatorService.cs (1)
244private static void ProcessUsings(SyntaxList<UsingDirectiveSyntax> usings, ArrayBuilder<TextSpan> spans, CancellationToken cancellationToken)
src\Analyzers\CSharp\Analyzers\MisplacedUsingDirectives\MisplacedUsingDirectivesDiagnosticAnalyzer.cs (2)
100IEnumerable<UsingDirectiveSyntax> usingDirectives, CodeStyleOption2<AddImportPlacement> option) 102foreach (var usingDirective in usingDirectives)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryImports\CSharpRemoveUnnecessaryImportsDiagnosticAnalyzer.cs (3)
24AbstractRemoveUnnecessaryImportsDiagnosticAnalyzer<UsingDirectiveSyntax> 37protected override ImmutableArray<SyntaxNode> MergeImports(ImmutableArray<UsingDirectiveSyntax> unnecessaryImports) 40protected override IUnnecessaryImportsProvider<UsingDirectiveSyntax> UnnecessaryImportsProvider
src\Analyzers\CSharp\CodeFixes\MisplacedUsingDirectives\MisplacedUsingDirectivesCodeFixProvider.cs (12)
105private static ImmutableArray<UsingDirectiveSyntax> GetAllUsingDirectives(CompilationUnitSyntax compilationUnit) 107using var _ = ArrayBuilder<UsingDirectiveSyntax>.GetInstance(out var result); 109foreach (var usingDirective in compilationUnit.Usings) 136ImmutableArray<UsingDirectiveSyntax> allUsingDirectives, 169Document document, CompilationUnitSyntax compilationUnit, ImmutableArray<UsingDirectiveSyntax> allUsingDirectives, CancellationToken cancellationToken) 185private static async Task<SyntaxNode> ExpandUsingDirectiveAsync(Document document, UsingDirectiveSyntax usingDirective, CancellationToken cancellationToken) 249private static (BaseNamespaceDeclarationSyntax namespaceWithoutUsings, ImmutableArray<UsingDirectiveSyntax> usingsFromNamespace) RemoveUsingsFromNamespace( 271private static (IEnumerable<UsingDirectiveSyntax> deduplicatedUsings, IEnumerable<SyntaxTrivia> orphanedTrivia) RemoveDuplicateUsings( 272IEnumerable<UsingDirectiveSyntax> existingUsings, 273ImmutableArray<UsingDirectiveSyntax> usingsToAdd) 277var deduplicatedUsingsBuilder = ImmutableArray.CreateBuilder<UsingDirectiveSyntax>(); 280foreach (var usingDirective in usingsToAdd)
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (1)
EditAndContinue\TopLevelEditingTests.cs (1)
82Assert.IsType<UsingDirectiveSyntax>(edits.Edits.First().OldNode);
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (28)
Semantics\AccessCheckTests.cs (2)
743IAliasSymbol aliasA = model.GetDeclaredSymbol(tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Where(u => u.Alias != null).Single()) as IAliasSymbol; 897IAliasSymbol SomeAlias = model.GetDeclaredSymbol(tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Where(u => u.Alias != null).Single());
Semantics\GlobalUsingDirectiveTests.cs (21)
3844var aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3870aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3890aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3901aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3918aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3934aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3954aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3968aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3979aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 3990aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4006aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4026aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4040aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4051aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4062aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4078aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4092aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4100aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4113aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4135aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray(); 4151aliases = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray();
Semantics\InteractiveUsingTests.cs (4)
87var syntax = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single(); 117var syntax = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single();
Semantics\SyntaxTreeRootTests.cs (1)
26var node = SyntaxFactory.UsingDirective(SyntaxFactory.IdentifierName("Blah"));
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (66)
Compilation\GetImportScopesTests.cs (28)
56Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax); 72Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax); 103Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax); 131Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax); 149Assert.True(scopes.Single().Imports.Any(i => i.DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } })); 150Assert.True(scopes.Single().Imports.Any(i => i.DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } })); 176Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 199Assert.True(scopes[0].Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } }); 201Assert.True(scopes[1].Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 227Assert.True(scopes[0].Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } }); 229Assert.True(scopes[1].Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 245Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax); 261Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax); 292Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax); 320Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax); 338Assert.True(scopes.Single().Aliases.Any(a => a.DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } })); 339Assert.True(scopes.Single().Aliases.Any(a => a.DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } })); 365Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 388Assert.True(scopes[0].Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } }); 390Assert.True(scopes[1].Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 623Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Alias.Name.Identifier.Text: "M" }); 626Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } }); 649Assert.True(scopes.Single().Imports.Single().DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax); 653Assert.True(scopes.Single().Aliases.Single().DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Alias.Name.Identifier.Text: "M" }); 683Assert.True(scopes.Single().Imports.Any(i => i.DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(System) } })); 685Assert.True(scopes.Single().Imports.Any(i => i.DeclaringSyntaxReference!.GetSyntax() is UsingDirectiveSyntax { Name: QualifiedNameSyntax { Right: IdentifierNameSyntax { Identifier.Text: nameof(System.IO) } } })); 689Assert.True(scopes.Single().Aliases.Any(i => i.DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: IdentifierNameSyntax { Identifier.Text: nameof(Microsoft) } })); 691Assert.True(scopes.Single().Aliases.Any(i => i.DeclaringSyntaxReferences.Single().GetSyntax() is UsingDirectiveSyntax { Name: QualifiedNameSyntax { Right: IdentifierNameSyntax { Identifier.Text: nameof(System.Threading) } } }));
Compilation\GetSemanticInfoBrokenCodeTests.cs (1)
200Assert.Empty(tree.GetCompilationUnitRoot().DescendantNodes().OfType<UsingDirectiveSyntax>());
Compilation\SemanticModelAPITests.cs (8)
1232var aliasSyntax = tree.GetCompilationUnitRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single(); 1341var usingSyntax = tree.GetCompilationUnitRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single(); 1728var aliasDecl = tree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single(); 2797var usingStatement = root.Usings[0]; 2812var usingStatement = root.Usings[0];
Compilation\SemanticModelGetDeclaredSymbolAPITests.cs (5)
1031var usingDirective = (UsingDirectiveSyntax)tree.FindNodeOrTokenByKind(SyntaxKind.UsingDirective).AsNode(); 2814var u1 = (UsingDirectiveSyntax)n2.Usings[0]; 3922var usingDirectives = tree.GetCompilationUnitRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray();
Compilation\UsedAssembliesTests.cs (2)
154foreach (var directive in unit.Usings) 174foreach (var directive in unit.Usings)
DocumentationComments\DocumentationCommentIDTests.cs (2)
31var syntax = tree.GetCompilationUnitRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().Single();
Symbols\Source\DeclaringSyntaxNodeTests.cs (3)
664CheckDeclaringSyntax<UsingDirectiveSyntax>(comp, tree, "ConsoleAlias", SymbolKind.Alias); 665CheckDeclaringSyntax<UsingDirectiveSyntax>(comp, tree, "ListOfIntAlias", SymbolKind.Alias); 666CheckDeclaringSyntax<UsingDirectiveSyntax>(comp, tree, "GooAlias", SymbolKind.Alias);
Symbols\Source\ExternAliasTests.cs (2)
480var usingSyntax = root.DescendantNodes().OfType<UsingDirectiveSyntax>().Single();
Symbols\Source\UsingAliasTests.cs (15)
34var usingAlias = root.Usings[0]; 91var usingAlias = root.Usings[0]; 151var usingAlias = root.Usings[0]; 206var usingAlias = root.Usings[0]; 271var usingAlias = root.Usings[0]; 298var usingAlias = root.Usings[0]; 344var usingAlias = root.Usings[0]; 385var usingAlias = root.Usings[0]; 406var usingAlias = root.Usings[0]; 425var usingAlias = root.Usings[0]; 444var usingAlias = root.Usings[0]; 463var usingAlias = root.Usings[0]; 482var usingAlias = root.Usings[0]; 503var usingAlias = root.Usings[0]; 523UsingDirectiveSyntax usingAlias = syntaxTree.GetCompilationUnitRoot().Usings.First();
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (26)
Generated\Syntax.Test.xml.Generated.cs (8)
10680=> SyntaxFactory.CompilationUnit(new SyntaxList<ExternAliasDirectiveSyntax>(), new SyntaxList<UsingDirectiveSyntax>(), new SyntaxList<AttributeListSyntax>(), new SyntaxList<MemberDeclarationSyntax>(), SyntaxFactory.Token(SyntaxKind.EndOfFileToken)); 10685private static UsingDirectiveSyntax GenerateUsingDirective() 10689=> SyntaxFactory.NamespaceDeclaration(new SyntaxList<AttributeListSyntax>(), new SyntaxTokenList(), SyntaxFactory.Token(SyntaxKind.NamespaceKeyword), GenerateIdentifierName(), SyntaxFactory.Token(SyntaxKind.OpenBraceToken), new SyntaxList<ExternAliasDirectiveSyntax>(), new SyntaxList<UsingDirectiveSyntax>(), new SyntaxList<MemberDeclarationSyntax>(), SyntaxFactory.Token(SyntaxKind.CloseBraceToken), default(SyntaxToken)); 10692=> SyntaxFactory.FileScopedNamespaceDeclaration(new SyntaxList<AttributeListSyntax>(), new SyntaxTokenList(), SyntaxFactory.Token(SyntaxKind.NamespaceKeyword), GenerateIdentifierName(), SyntaxFactory.Token(SyntaxKind.SemicolonToken), new SyntaxList<ExternAliasDirectiveSyntax>(), new SyntaxList<UsingDirectiveSyntax>(), new SyntaxList<MemberDeclarationSyntax>()); 12833var node = GenerateUsingDirective(); 12842var newNode = node.WithGlobalKeyword(node.GlobalKeyword).WithUsingKeyword(node.UsingKeyword).WithStaticKeyword(node.StaticKeyword).WithUnsafeKeyword(node.UnsafeKeyword).WithAlias(node.Alias).WithNamespaceOrType(node.NamespaceOrType).WithSemicolonToken(node.SemicolonToken); 18051var oldNode = GenerateUsingDirective(); 18067var oldNode = GenerateUsingDirective();
Parsing\DeclarationParsingTests.cs (7)
62var ud = file.Usings[0]; 84var ud = file.Usings[0]; 151var ud = file.Usings[0]; 173var ud = file.Usings[0]; 195var ud = file.Usings[0]; 217var ud = file.Usings[0]; 241var ud = file.Usings[0];
Syntax\SyntaxFactoryTests.cs (1)
34var usingDirective = SyntaxFactory.UsingDirective(SyntaxFactory.Token(SyntaxKind.StaticKeyword), null, someValidName);
Syntax\SyntaxNodeTests.cs (10)
3652var FirstUsingClause = root.Usings[0]; 3653var SecondUsingClause = root.Usings[1]; 3654var ThirdUsingClause = root.Usings[2]; 3662UsingDirectiveSyntax newUsingClause = ThirdUsingClause.WithName(name); 3702var FirstUsingClause = root.Usings[0]; 3703var SecondUsingClause = root.Usings[1]; 3704var ThirdUsingClause = root.Usings[2]; 3735var FirstUsingClause = root.Usings[0]; 3736var SecondUsingClause = root.Usings[1]; 3737var ThirdUsingClause = root.Usings[2];
Microsoft.CodeAnalysis.CSharp.Test.Utilities (1)
Extensions.cs (1)
660declaration is UsingDirectiveSyntax ||
Microsoft.CodeAnalysis.CSharp.Workspaces (114)
Classification\SyntaxClassification\UsingDirectiveSyntaxClassifier.cs (3)
26if (syntax is UsingDirectiveSyntax usingDirective) 32public override ImmutableArray<Type> SyntaxNodeTypes { get; } = [typeof(UsingDirectiveSyntax)]; 35UsingDirectiveSyntax usingDirective,
CodeGeneration\CSharpSyntaxGenerator.cs (5)
112private SyntaxList<UsingDirectiveSyntax> AsUsingDirectives(IEnumerable<SyntaxNode> declarations) 115? [.. declarations.Select(this.AsUsingDirective).OfType<UsingDirectiveSyntax>()] 126return node as UsingDirectiveSyntax; 1888UsingDirectiveSyntax usingDirective => usingDirective.Name?.ToString() ?? string.Empty, 1918UsingDirectiveSyntax usingDeclaration => ReplaceWithTrivia(declaration, usingDeclaration.NamespaceOrType, this.DottedName(name)),
FindSymbols\CSharpDeclaredSymbolInfoFactoryService.cs (6)
30UsingDirectiveSyntax, 107private static void ProcessUsings(List<Dictionary<string, string>> aliasMaps, SyntaxList<UsingDirectiveSyntax> usings) 111foreach (var usingDecl in usings) 470protected override SyntaxList<UsingDirectiveSyntax> GetUsingAliases(CompilationUnitSyntax node) 473protected override SyntaxList<UsingDirectiveSyntax> GetUsingAliases(BaseNamespaceDeclarationSyntax node) 670UsingDirectiveSyntax usingDirectiveNode, out ImmutableArray<(string aliasName, string name)> aliases)
Recommendations\CSharpRecommendationServiceRunner.cs (1)
565var usingDirective = name.GetAncestorOrThis<UsingDirectiveSyntax>();
Rename\CSharpRenameRewriterLanguageService.cs (4)
870var currentUsing = (UsingDirectiveSyntax)token.Parent!.Parent!.Parent!; 873SyntaxList<UsingDirectiveSyntax> usings; 884foreach (var usingDirective in usings)
Simplification\CSharpSimplificationService.cs (1)
195if (root.FindNode(diagnostic.Location.SourceSpan) is UsingDirectiveSyntax node)
Simplification\Simplifiers\AbstractCSharpSimplifier.cs (2)
238foreach (var usingDirective in usings) 342var usingDirective = startNode.GetAncestorOrThis<UsingDirectiveSyntax>();
Simplification\Simplifiers\ExpressionSimplifier.cs (1)
148var declIdentifier = ((UsingDirectiveSyntax)syntaxRef.GetSyntax(cancellationToken)).Alias!.Name.Identifier;
Simplification\Simplifiers\NameSimplifier.cs (2)
124var declIdentifier = ((UsingDirectiveSyntax)syntaxRef.GetSyntax(cancellationToken)).Alias.Name.Identifier; 692if (name?.Parent is UsingDirectiveSyntax usingDirective &&
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SemanticModelExtensions.cs (1)
166foreach (var @using in location.GetEnclosingUsingDirectives())
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (2)
306public static IEnumerable<UsingDirectiveSyntax> GetEnclosingUsingDirectives(this SyntaxNode node) 372var usingDirectiveAncestor = contextNode.GetAncestor<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\AnchorIndentationFormattingRule.cs (1)
54case UsingDirectiveSyntax usingNode:
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\ElasticTriviaFormattingRule.cs (2)
462else if (previousToken.Parent is UsingDirectiveSyntax) 464return currentToken.Parent is UsingDirectiveSyntax ? 1 : 2;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\TokenBasedFormattingRule.cs (3)
230if (previousToken.Parent is not UsingDirectiveSyntax previousUsing) 237currentToken.Parent is UsingDirectiveSyntax currentUsing && 256private static SyntaxList<UsingDirectiveSyntax> GetUsings(SyntaxNode node)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Helpers\RemoveUnnecessaryImports\CSharpUnnecessaryImportsProvider.cs (4)
15: AbstractUnnecessaryImportsProvider<UsingDirectiveSyntax> 23public override ImmutableArray<UsingDirectiveSyntax> GetUnnecessaryImports( 32using var _ = ArrayBuilder<UsingDirectiveSyntax>.GetInstance(out var result); 36root.FindNode(diagnostic.Location.SourceSpan) is UsingDirectiveSyntax node && predicate(node))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SemanticFacts\CSharpSemanticFacts.cs (2)
145private static void AppendAliasNames(SyntaxList<UsingDirectiveSyntax> usings, ImmutableHashSet<string>.Builder builder) 147foreach (var @using in usings)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (4)
196=> node?.Parent is UsingDirectiveSyntax usingDirective && 200=> node is UsingDirectiveSyntax usingDirectiveNode && usingDirectiveNode.Alias != null; 204var usingDirective = (UsingDirectiveSyntax)node;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\FormattingRangeHelper.cs (1)
120if (parent is UsingDirectiveSyntax or
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\UsingsAndExternAliasesDirectiveComparer.cs (5)
46private static UsingKind GetUsingKind(UsingDirectiveSyntax? usingDirective, ExternAliasDirectiveSyntax? externDirective) 90var using1 = directive1 as UsingDirectiveSyntax; 91var using2 = directive2 as UsingDirectiveSyntax;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Utilities\UsingsAndExternAliasesOrganizer.cs (11)
18SyntaxList<UsingDirectiveSyntax> usingList, 23out SyntaxList<UsingDirectiveSyntax> organizedUsingList) 42var firstUsing = organizedUsingList[0]; 53var lastUsing = organizedUsingList[i - 1]; 54var currentUsing = organizedUsingList[i]; 67UsingDirectiveSyntax using1, 68UsingDirectiveSyntax using2) 106SyntaxList<UsingDirectiveSyntax> usingList, 110out SyntaxList<UsingDirectiveSyntax> organizedUsingList) 148.Where(t => t is UsingDirectiveSyntax) 149.Cast<UsingDirectiveSyntax>()];
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CodeGeneration\NamespaceGenerator.cs (2)
139private static SyntaxList<UsingDirectiveSyntax> GenerateUsingDirectives(INamespaceSymbol innermostNamespace) 150private static UsingDirectiveSyntax? GenerateUsingDirective(ISymbol symbol)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\BaseNamespaceDeclarationSyntaxExtensions.cs (2)
15IList<UsingDirectiveSyntax> usingDirectives, 22var newUsings = new List<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\CompilationUnitSyntaxExtensions.cs (6)
68UsingDirectiveSyntax usingDirective, 78IList<UsingDirectiveSyntax> usingDirectives, 102IList<UsingDirectiveSyntax> usingDirectives, 140private static List<UsingDirectiveSyntax> AddUsingDirectives( 141CompilationUnitSyntax root, IList<UsingDirectiveSyntax> usingDirectives) 144var usings = new List<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\CSharpSyntaxContext.cs (3)
274isInImportsDirective: leftToken.GetAncestor<UsingDirectiveSyntax>() != null, 297isRightAfterUsingOrImportDirective: targetToken.Parent is UsingDirectiveSyntax usingDirective && usingDirective?.GetLastToken() == targetToken, 431var usingDirective = leftToken.GetAncestor<UsingDirectiveSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTokenExtensions.cs (4)
27var usingDirective = token.GetAncestor<UsingDirectiveSyntax>(); 41if (token is { RawKind: (int)SyntaxKind.StaticKeyword, Parent: UsingDirectiveSyntax }) 48token.GetPreviousToken() is { RawKind: (int)SyntaxKind.StaticKeyword, Parent: UsingDirectiveSyntax }) 508targetToken.GetAncestors<UsingDirectiveSyntax>().Any(d => d.UnsafeKeyword.IsKind(SyntaxKind.UnsafeKeyword));
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (4)
419(nextToken.Kind() == SyntaxKind.GlobalKeyword && nextToken.GetAncestor<UsingDirectiveSyntax>()?.GlobalKeyword == nextToken)) 581if (token.GetAncestor<UsingDirectiveSyntax>() is not null) 645var usingDirective = token.GetAncestor<UsingDirectiveSyntax>(); 794token.GetAncestor<UsingDirectiveSyntax>() != null)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ITypeSymbolExtensions.cs (2)
126foreach (var applicableUsing in applicableUsings) 143private static IEnumerable<UsingDirectiveSyntax> GetApplicableUsings(int position, SyntaxNode root)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\UsingDirectiveSyntaxExtensions.cs (2)
15this List<UsingDirectiveSyntax> usingDirectives, 16SyntaxList<UsingDirectiveSyntax> existingDirectives,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpAddImportsService.cs (13)
27CompilationUnitSyntax, BaseNamespaceDeclarationSyntax, UsingDirectiveSyntax, ExternAliasDirectiveSyntax> 39protected override SyntaxNode? GetAlias(UsingDirectiveSyntax usingOrAlias) 42protected override bool IsStaticUsing(UsingDirectiveSyntax usingOrAlias) 47UsingDirectiveSyntax[] usingDirectives, 48UsingDirectiveSyntax[] staticUsingDirectives, 49UsingDirectiveSyntax[] aliasDirectives, 67protected override SyntaxList<UsingDirectiveSyntax> GetUsingsAndAliases(SyntaxNode node) 94private readonly UsingDirectiveSyntax[] _aliasDirectives; 96private readonly UsingDirectiveSyntax[] _usingDirectives; 97private readonly UsingDirectiveSyntax[] _staticUsingDirectives; 101UsingDirectiveSyntax[] usingDirectives, 102UsingDirectiveSyntax[] staticUsingDirectives, 103UsingDirectiveSyntax[] aliasDirectives,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpRemoveUnnecessaryImportsService.cs (2)
27AbstractRemoveUnnecessaryImportsService<UsingDirectiveSyntax> 34protected override IUnnecessaryImportsProvider<UsingDirectiveSyntax> UnnecessaryImportsProvider
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpRemoveUnnecessaryImportsService.Rewriter.cs (13)
25private readonly ISet<UsingDirectiveSyntax> _unnecessaryUsingsDoNotAccessDirectly; 29ISet<UsingDirectiveSyntax> unnecessaryUsings, 44SyntaxList<UsingDirectiveSyntax> usings, 45ISet<UsingDirectiveSyntax> usingsToRemove, 46out SyntaxList<UsingDirectiveSyntax> finalUsings, 49var currentUsings = new List<UsingDirectiveSyntax>(usings); 58var currentUsing = currentUsings[i]; 73var nextUsing = currentUsings[nextIndex]; 114var currentUsing = currentUsings[i]; 129private ISet<UsingDirectiveSyntax> GetUsingsToRemove( 130SyntaxList<UsingDirectiveSyntax> oldUsings, 131SyntaxList<UsingDirectiveSyntax> newUsings) 135var result = new HashSet<UsingDirectiveSyntax>();
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (3)
CodeGeneration\SyntaxGeneratorTests.cs (3)
1735VerifySyntax<UsingDirectiveSyntax>( 1739VerifySyntax<UsingDirectiveSyntax>( 1743VerifySyntax<UsingDirectiveSyntax>(
Microsoft.CodeAnalysis.Workspaces.UnitTests (1)
SymbolKeyTests.cs (1)
679var symbols = tree.GetRoot().DescendantNodes().OfType<CSharp.Syntax.UsingDirectiveSyntax>().Select(s => model.GetDeclaredSymbol(s)).ToList();
Microsoft.VisualStudio.LanguageServices.CSharp (20)
CodeModel\CSharpCodeModelService.cs (9)
249((UsingDirectiveSyntax)node).Name != null) 532return CreateInternalCodeImport(state, fileCodeModel, (UsingDirectiveSyntax)node); 788=> node is UsingDirectiveSyntax; 1551foreach (UsingDirectiveSyntax usingDirective in GetImportNodes(parentNode)) 1819if (importNode is UsingDirectiveSyntax usingDirective) 1831if (importNode is UsingDirectiveSyntax usingDirective) 1841if (importNode is UsingDirectiveSyntax usingDirective) 3459var import = (UsingDirectiveSyntax)importNode;
CodeModel\CSharpCodeModelService.NodeLocator.cs (4)
71return GetStartPoint(text, (UsingDirectiveSyntax)node, part); 122return GetEndPoint(text, (UsingDirectiveSyntax)node, part); 645private static VirtualTreePoint GetStartPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part) 1184private static VirtualTreePoint GetEndPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
LanguageService\CSharpHelpContextService.cs (3)
436case SyntaxKind.UsingKeyword when token.Parent is UsingDirectiveSyntax: 441case SyntaxKind.StaticKeyword when token.Parent is UsingDirectiveSyntax: 444case SyntaxKind.GlobalKeyword when token.Parent is UsingDirectiveSyntax:
Snippets\CSharpSnippetExpansionLanguageHelper.cs (4)
108private static List<UsingDirectiveSyntax> GetUsingDirectivesToAdd( 113var newUsings = new List<UsingDirectiveSyntax>(); 129var candidateUsing = SyntaxFactory.ParseCompilationUnit("using " + namespaceToImport + ";").DescendantNodes().OfType<UsingDirectiveSyntax>().FirstOrDefault();
System.Windows.Forms.Analyzers.CodeFixes.CSharp (3)
System\Windows\Forms\CSharp\CodeFixes\AddDesignerSerializationVisibility\AddDesignerSerializationVisibilityCodeFixProvider.cs (3)
102.OfType<UsingDirectiveSyntax>() 111.OfType<UsingDirectiveSyntax>() 138UsingDirectiveSyntax usingDirective = SyntaxFactory