Skip to content

Commit 9cdda59

Browse files
Use object pattern
1 parent 6250c52 commit 9cdda59

8 files changed

Lines changed: 14 additions & 15 deletions

File tree

CodeConverter/CSharp/DeclarationNodeVisitor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,8 @@ public override async Task<CSharpSyntaxNode> VisitAccessorBlock(VBSyntax.Accesso
897897
var attributes = await CommonConversions.ConvertAttributesAsync(node.AccessorStatement.AttributeLists);
898898
var modifiers = CommonConversions.ConvertModifiers(node, node.AccessorStatement.Modifiers, TokenContext.Local);
899899
string potentialMethodId;
900-
var declaredParentSymbol = containingPropertyStmt != null ? _semanticModel.GetDeclaredSymbol(containingPropertyStmt) : null;
901-
var explicitInterfaceSpecifier = declaredParentSymbol is IPropertySymbol propSymbol && propSymbol.DeclaredAccessibility == Accessibility.Private && propSymbol.ExplicitInterfaceImplementations.Any() ?
900+
var declaredPropSymbol = containingPropertyStmt != null ? _semanticModel.GetDeclaredSymbol(containingPropertyStmt) : null;
901+
var explicitInterfaceSpecifier = declaredPropSymbol is { } propSymbol && propSymbol.DeclaredAccessibility == Accessibility.Private && propSymbol.ExplicitInterfaceImplementations.Any() ?
902902
SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.IdentifierName(propSymbol.ExplicitInterfaceImplementations.First().ContainingType.Name))
903903
: null;
904904
var sourceMap = ancestoryPropertyBlock?.Accessors.FirstOrDefault() == node ? SourceTriviaMapKind.All : SourceTriviaMapKind.None;
@@ -1012,7 +1012,7 @@ private BlockSyntax WithImplicitReturnStatements(VBSyntax.MethodBlockBaseSyntax
10121012
IdentifierNameSyntax csReturnVariableOrNull)
10131013
{
10141014
if (!node.MustReturn()) return convertedStatements;
1015-
if (_semanticModel.GetDeclaredSymbol(node) is IMethodSymbol ms && ms.ReturnsVoidOrAsyncTask()) {
1015+
if (_semanticModel.GetDeclaredSymbol(node) is { } ms && ms.ReturnsVoidOrAsyncTask()) {
10161016
return convertedStatements;
10171017
}
10181018

CodeConverter/CSharp/ExpressionNodeVisitor.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ public override async Task<CSharpSyntaxNode> VisitUnaryExpression(VBasic.Syntax.
662662
}
663663
var kind = VBasic.VisualBasicExtensions.Kind(node).ConvertToken(TokenContext.Local);
664664
SyntaxKind csTokenKind = CSharpUtil.GetExpressionOperatorTokenKind(kind);
665-
if (kind == SyntaxKind.LogicalNotExpression && await NegateAndSimplifyOrNullAsync(node, expr) is ExpressionSyntax simpleNegation) {
665+
if (kind == SyntaxKind.LogicalNotExpression && await NegateAndSimplifyOrNullAsync(node, expr) is { } simpleNegation) {
666666
return AsBool(node, simpleNegation);
667667
}
668668
return SyntaxFactory.PrefixUnaryExpression(
@@ -679,7 +679,7 @@ private ExpressionSyntax AsBool(VBSyntax.UnaryExpressionSyntax node, ExpressionS
679679

680680
private async Task<ExpressionSyntax> NegateAndSimplifyOrNullAsync(VBSyntax.UnaryExpressionSyntax node, ExpressionSyntax expr)
681681
{
682-
if (await _operatorConverter.ConvertNothingComparisonOrNullAsync(node.Operand.SkipIntoParens(), true) is ExpressionSyntax nothingComparison) {
682+
if (await _operatorConverter.ConvertNothingComparisonOrNullAsync(node.Operand.SkipIntoParens(), true) is { } nothingComparison) {
683683
return nothingComparison;
684684
} else if (expr is BinaryExpressionSyntax bes && bes.OperatorToken.IsKind(SyntaxKind.EqualsToken)) {
685685
return bes.WithOperatorToken(SyntaxFactory.Token(SyntaxKind.ExclamationEqualsToken));
@@ -700,7 +700,7 @@ private CSharpSyntaxNode ConvertAddressOf(VBSyntax.UnaryExpressionSyntax node, E
700700

701701
public override async Task<CSharpSyntaxNode> VisitBinaryExpression(VBasic.Syntax.BinaryExpressionSyntax node)
702702
{
703-
if (await _operatorConverter.ConvertRewrittenBinaryOperatorOrNullAsync(node) is ExpressionSyntax operatorNode) {
703+
if (await _operatorConverter.ConvertRewrittenBinaryOperatorOrNullAsync(node) is { } operatorNode) {
704704
return operatorNode;
705705
}
706706

@@ -809,8 +809,7 @@ private async Task<CSharpSyntaxNode> ConvertInvocationAsync(VBSyntax.InvocationE
809809
expressionSymbol?.GetReturnType() ?? _semanticModel.GetTypeInfo(node.Expression).Type;
810810
var operation = _semanticModel.GetOperation(node);
811811
if (expressionSymbol?.ContainingNamespace.MetadataName == nameof(Microsoft.VisualBasic) &&
812-
(await SubstituteVisualBasicMethodOrNullAsync(node) ?? await WithRemovedRedundantConversionOrNullAsync(node, expressionSymbol)) is
813-
CSharpSyntaxNode csEquivalent) {
812+
(await SubstituteVisualBasicMethodOrNullAsync(node) ?? await WithRemovedRedundantConversionOrNullAsync(node, expressionSymbol)) is { } csEquivalent) {
814813
return csEquivalent;
815814
}
816815

CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public override async Task<SyntaxList<StatementSyntax>> VisitForEachBlock(VBSynt
600600
var declaration = (await SplitVariableDeclarationsAsync(vds)).Variables.Single().Decl;
601601
type = declaration.Type;
602602
id = declaration.Variables.Single().Identifier;
603-
} else if (_semanticModel.GetSymbolInfo(stmt.ControlVariable).Symbol is ISymbol varSymbol) {
603+
} else if (_semanticModel.GetSymbolInfo(stmt.ControlVariable).Symbol is { } varSymbol) {
604604
var variableType = varSymbol.GetSymbolType();
605605
var explicitCastWouldHaveNoEffect = variableType?.SpecialType == SpecialType.System_Object || _semanticModel.GetTypeInfo(stmt.Expression).ConvertedType.IsEnumerableOfExactType(variableType);
606606
type = CommonConversions.GetTypeSyntax(varSymbol.GetSymbolType(), explicitCastWouldHaveNoEffect);

CodeConverter/CSharp/TypeConversionAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ invoke.Expression is MemberAccessExpressionSyntax expr &&
270270
return csNode;
271271
}
272272

273-
if (GetToStringConversionOrNull(csNode, currentType, targetType) is ExpressionSyntax csNodeToString) return csNodeToString;
273+
if (GetToStringConversionOrNull(csNode, currentType, targetType) is { } csNodeToString) return csNodeToString;
274274

275275
if (!ExpressionEvaluator.ConversionsTypeFullNames.TryGetValue(targetType.GetFullMetadataName(), out var methodId)) {
276276
return CreateCast(csNode, targetType);

CodeConverter/Shared/DefaultReferences.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static (string Location, string[] ReferenceNames) GetAssemblyInfo(string
7373
{
7474
if (_assemblyInfoCache.TryGetValue(assemblyName, out var assemblyInfo)) {
7575
return assemblyInfo;
76-
} else if (LoadOrNull(assemblyName) is Assembly a) {
76+
} else if (LoadOrNull(assemblyName) is { } a) {
7777
return GetAssemblyInfo(a);
7878
}
7979

CodeConverter/Util/ObjectExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static TResult TypeSwitch<TBaseType, TDerivedType1, TDerivedType2, TResul
1414
return matchFunc1(tObj);
1515
case TDerivedType2 tObj:
1616
return matchFunc2(tObj);
17-
case TBaseType tObj when (defaultFunc != null):
17+
case { } tObj when (defaultFunc != null):
1818
return defaultFunc(tObj);
1919
default:
2020
return default(TResult);
@@ -33,7 +33,7 @@ public static TResult TypeSwitch<TBaseType, TDerivedType1, TDerivedType2, TDeriv
3333
return matchFunc2(tObj);
3434
case TDerivedType3 tObj:
3535
return matchFunc3(tObj);
36-
case TBaseType tObj when (defaultFunc != null):
36+
case { } tObj when (defaultFunc != null):
3737
return defaultFunc(tObj);
3838
default:
3939
return default(TResult);

CodeConverter/VB/NodesVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ public override VisualBasicSyntaxNode VisitDefaultExpression(CSS.DefaultExpressi
11941194
private VisualBasicSyntaxNode CreateTypedNothing(CSS.ExpressionSyntax node)
11951195
{
11961196
var nothing = VisualBasicSyntaxFactory.NothingExpression;
1197-
return _semanticModel.GetTypeInfo(node).ConvertedType is ITypeSymbol t
1197+
return _semanticModel.GetTypeInfo(node).ConvertedType is { } t
11981198
? (VisualBasicSyntaxNode) _commonConversions.VbSyntaxGenerator.CastExpression(t, nothing)
11991199
: nothing;
12001200
}

CommandLine/CodeConv.Shared/CodeConvProgram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async Task<int> ExecuteAsync()
7474
// Ideally we'd be able to use MSBuildLocator.QueryVisualStudioInstances(DiscoveryType.VisualStudioSetup) from .NET core, but it will never be supported: https://github.com/microsoft/MSBuildLocator/issues/61
7575
// Instead, if MSBuild 16.0+ is available, start a .NET framework process and let it run with that
7676
if (_runningInNetCore && !CoreOnlyProjects) {
77-
if (await GetLatestMsBuildExePathAsync() is string latestMsBuildExePath) {
77+
if (await GetLatestMsBuildExePathAsync() is { } latestMsBuildExePath) {
7878
return await RunNetFrameworkExeAsync(latestMsBuildExePath);
7979
} else {
8080
Console.WriteLine($"Using dot net SDK MSBuild which only works for dot net core projects.");

0 commit comments

Comments
 (0)