/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Analyzers/Core/CodeFixes/Naming/NamingExtensions.cs
40 строк
2 KB
Cyrus Najmabadi
Remove unnecessary imports
10 мар 2025, 17:04
10 мар 2025, 17:04
58c992f
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeStyle; using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; using Microsoft.CodeAnalysis.Shared.Naming; namespace Microsoft.CodeAnalysis.Shared.Extensions; internal static class NamingExtensions { public static async Task<NamingRule> GetApplicableNamingRuleAsync( this Document document, SymbolKind symbolKind, Accessibility accessibility, CancellationToken cancellationToken) { var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false); foreach (var rule in rules) { if (rule.SymbolSpecification.AppliesTo(symbolKind, accessibility)) return rule; } throw ExceptionUtilities.Unreachable(); } /// <summary> /// Gets the set of naming rules the user has set for this document. Will include a set of default naming rules /// that match if the user hasn't specified any for a particular symbol type. The are added at the end so they /// will only be used if the user hasn't specified a preference. /// </summary> public static async Task<ImmutableArray<NamingRule>> GetNamingRulesAsync( this Document document, CancellationToken cancellationToken) { var options = await document.GetNamingStylePreferencesAsync(cancellationToken).ConfigureAwait(false); return options.Rules.NamingRules.AddRange(FallbackNamingRules.Default); } }