/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Analyzers/CSharp/CodeFixes/UseCollectionInitializer/CSharpUseCollectionInitializerCodeFixProvider.cs
51 строка
2 KB
Cyrus Najmabadi
ordering
07 июл 2025, 20:42
07 июл 2025, 20:42
f686152
Код
Авторство
О чём код?
// 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.Composition; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.UseCollectionExpression; using Microsoft.CodeAnalysis.UseCollectionInitializer; namespace Microsoft.CodeAnalysis.CSharp.UseCollectionInitializer; [ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.UseCollectionInitializer), Shared] [ExtensionOrder(Before = PredefinedCodeFixProviderNames.UseImplicitObjectCreation)] [method: ImportingConstructor] [method: SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")] internal sealed partial class CSharpUseCollectionInitializerCodeFixProvider() : AbstractUseCollectionInitializerCodeFixProvider< SyntaxKind, ExpressionSyntax, StatementSyntax, BaseObjectCreationExpressionSyntax, MemberAccessExpressionSyntax, InvocationExpressionSyntax, ExpressionStatementSyntax, LocalDeclarationStatementSyntax, VariableDeclaratorSyntax, CSharpUseCollectionInitializerAnalyzer> { protected override CSharpUseCollectionInitializerAnalyzer GetAnalyzer() => CSharpUseCollectionInitializerAnalyzer.Allocate(); protected override async Task<(SyntaxNode, SyntaxNode)> GetReplacementNodesAsync( Document document, BaseObjectCreationExpressionSyntax objectCreation, bool useCollectionExpression, ImmutableArray<CollectionMatch<SyntaxNode>> preMatches, ImmutableArray<CollectionMatch<SyntaxNode>> postMatches, CancellationToken cancellationToken) { ExpressionSyntax newObjectCreation = useCollectionExpression ? await CreateCollectionExpressionAsync(document, objectCreation, preMatches, postMatches, cancellationToken).ConfigureAwait(false) : CreateObjectInitializerExpression(objectCreation, postMatches); return (objectCreation, newObjectCreation); } }