@@ -35,7 +35,6 @@ internal class ExpressionNodeVisitor : VBasic.VisualBasicSyntaxVisitor<Task<CSha
35
35
private readonly QueryConverter _queryConverter ;
36
36
private readonly Lazy < IReadOnlyDictionary < ITypeSymbol , string > > _convertMethodsLookupByReturnType ;
37
37
private readonly LambdaConverter _lambdaConverter ;
38
- private readonly INamedTypeSymbol _vbBooleanTypeSymbol ;
39
38
private readonly VisualBasicNullableExpressionsConverter _visualBasicNullableTypesConverter ;
40
39
private readonly Dictionary < string , Stack < ( SyntaxNode Scope , string TempName ) > > _tempNameForAnonymousScope = new ( ) ;
41
40
private readonly HashSet < string > _generatedNames = new ( StringComparer . OrdinalIgnoreCase ) ;
@@ -58,7 +57,6 @@ public ExpressionNodeVisitor(SemanticModel semanticModel,
58
57
// If this isn't needed, the assembly with Conversions may not be referenced, so this must be done lazily
59
58
_convertMethodsLookupByReturnType =
60
59
new Lazy < IReadOnlyDictionary < ITypeSymbol , string > > ( ( ) => CreateConvertMethodsLookupByReturnType ( semanticModel ) ) ;
61
- _vbBooleanTypeSymbol = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Boolean" ) ;
62
60
}
63
61
64
62
private static IReadOnlyDictionary < ITypeSymbol , string > CreateConvertMethodsLookupByReturnType (
@@ -775,7 +773,7 @@ public override async Task<CSharpSyntaxNode> VisitBinaryConditionalExpression(VB
775
773
public override async Task < CSharpSyntaxNode > VisitTernaryConditionalExpression ( VBasic . Syntax . TernaryConditionalExpressionSyntax node )
776
774
{
777
775
var condition = await node . Condition . AcceptAsync < ExpressionSyntax > ( TriviaConvertingExpressionVisitor ) ;
778
- condition = CommonConversions . TypeConversionAnalyzer . AddExplicitConversion ( node . Condition , condition , forceTargetType : _vbBooleanTypeSymbol ) ;
776
+ condition = CommonConversions . TypeConversionAnalyzer . AddExplicitConversion ( node . Condition , condition , forceTargetType : CommonConversions . KnownTypes . Boolean ) ;
779
777
780
778
var whenTrue = await node . WhenTrue . AcceptAsync < ExpressionSyntax > ( TriviaConvertingExpressionVisitor ) ;
781
779
whenTrue = CommonConversions . TypeConversionAnalyzer . AddExplicitConversion ( node . WhenTrue , whenTrue ) ;
@@ -900,7 +898,7 @@ private async Task<CSharpSyntaxNode> ConvertBinaryExpressionAsync(VBasic.Syntax.
900
898
omitConversion = lhsTypeInfo . Type . SpecialType == SpecialType . System_String ||
901
899
rhsTypeInfo . Type . SpecialType == SpecialType . System_String ;
902
900
if ( lhsTypeInfo . ConvertedType . SpecialType != SpecialType . System_String ) {
903
- forceLhsTargetType = _semanticModel . Compilation . GetTypeByMetadataName ( "System. String" ) ;
901
+ forceLhsTargetType = CommonConversions . KnownTypes . String ;
904
902
}
905
903
}
906
904
}
@@ -938,6 +936,8 @@ private async Task<CSharpSyntaxNode> ConvertBinaryExpressionAsync(VBasic.Syntax.
938
936
return node . Parent . IsKind ( VBasic . SyntaxKind . SimpleArgument ) ? exp : exp . AddParens ( ) ;
939
937
}
940
938
939
+
940
+
941
941
private async Task < ExpressionSyntax > RewriteBinaryOperatorOrNullAsync ( VBSyntax . BinaryExpressionSyntax node ) =>
942
942
await _operatorConverter . ConvertRewrittenBinaryOperatorOrNullAsync ( node , TriviaConvertingExpressionVisitor . IsWithinQuery ) ;
943
943
@@ -1837,7 +1837,7 @@ private ArgumentSyntax CreateOptionalRefArg(IParameterSymbol p, RefKind refKind)
1837
1837
1838
1838
bool HasOptionalAttribute ( IParameterSymbol p )
1839
1839
{
1840
- var optionalAttribute = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Runtime.InteropServices. OptionalAttribute" ) ;
1840
+ var optionalAttribute = CommonConversions . KnownTypes . OptionalAttribute ;
1841
1841
if ( optionalAttribute == null ) {
1842
1842
return false ;
1843
1843
}
@@ -1849,7 +1849,7 @@ bool TryGetDefaultParameterValueAttributeValue(IParameterSymbol p, out object de
1849
1849
{
1850
1850
defaultValue = null ;
1851
1851
1852
- var defaultParameterValueAttribute = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Runtime.InteropServices. DefaultParameterValueAttribute" ) ;
1852
+ var defaultParameterValueAttribute = CommonConversions . KnownTypes . DefaultParameterValueAttribute ;
1853
1853
if ( defaultParameterValueAttribute == null ) {
1854
1854
return false ;
1855
1855
}
@@ -1941,7 +1941,7 @@ private ISymbol GetInvocationSymbol(SyntaxNode invocation)
1941
1941
( VBSyntax . InvocationExpressionSyntax e ) => _semanticModel . GetSymbolInfo ( e ) . ExtractBestMatch < ISymbol > ( ) ,
1942
1942
( VBSyntax . ObjectCreationExpressionSyntax e ) => _semanticModel . GetSymbolInfo ( e ) . ExtractBestMatch < ISymbol > ( ) ,
1943
1943
( VBSyntax . RaiseEventStatementSyntax e ) => _semanticModel . GetSymbolInfo ( e . Name ) . ExtractBestMatch < ISymbol > ( ) ,
1944
- ( VBSyntax . MidExpressionSyntax _ ) => _semanticModel . Compilation . GetTypeByMetadataName ( "Microsoft.VisualBasic.CompilerServices.StringType" ) ? . GetMembers ( "MidStmtStr" ) . FirstOrDefault ( ) ,
1944
+ ( VBSyntax . MidExpressionSyntax _ ) => CommonConversions . KnownTypes . VbCompilerStringType ? . GetMembers ( "MidStmtStr" ) . FirstOrDefault ( ) ,
1945
1945
_ => throw new NotSupportedException ( ) ) ;
1946
1946
return symbol ;
1947
1947
}
0 commit comments