/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Workspaces/CSharp/Portable/Simplification/Reducers/CSharpVarReducer.Rewriter.cs
60 строк
3 KB
Cyrus Najmabadi
perform all computation up front
18 сен 2025, 23:55
18 сен 2025, 23:55
4382acf
Код
Авторство
О чём код?
// 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. #nullable disable using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Utilities; using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Simplification; namespace Microsoft.CodeAnalysis.CSharp.Simplification; internal sealed partial class CSharpVarReducer { private sealed class Rewriter : AbstractReductionRewriter { public Rewriter(ObjectPool<IReductionRewriter> pool) : base(pool) { } private SyntaxNode ProcessTypeSyntax(TypeSyntax typeSyntax) { this.CancellationToken.ThrowIfCancellationRequested(); // Only simplify if us, or a parent, was marked as needing simplification. if (!alwaysSimplify && !typeSyntax.HasAnnotation(Simplifier.Annotation)) { return typeSyntax; } // Definitely do not simplify us if we were told to not simplify. if (typeSyntax.HasAnnotation(SimplificationHelpers.DoNotSimplifyAnnotation)) { return typeSyntax; } var typeStyle = CSharpUseImplicitTypeHelper.Instance.AnalyzeTypeName( typeSyntax, this.SemanticModel, this.Options, this.CancellationToken); if (!typeStyle.IsStylePreferred || !typeStyle.CanConvert) return typeSyntax; return SyntaxFactory.IdentifierName("var") .WithLeadingTrivia(typeSyntax.GetLeadingTrivia()) .WithTrailingTrivia(typeSyntax.GetTrailingTrivia()); } public override SyntaxNode VisitAliasQualifiedName(AliasQualifiedNameSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitArrayType(ArrayTypeSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitGenericName(GenericNameSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitNullableType(NullableTypeSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitPointerType(PointerTypeSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitPredefinedType(PredefinedTypeSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitQualifiedName(QualifiedNameSyntax node) => ProcessTypeSyntax(node); public override SyntaxNode VisitTupleType(TupleTypeSyntax node) => ProcessTypeSyntax(node); } }