@@ -35,7 +35,6 @@ internal class ExpressionNodeVisitor : VBasic.VisualBasicSyntaxVisitor<Task<CSha
3535 private readonly QueryConverter _queryConverter ;
3636 private readonly Lazy < IReadOnlyDictionary < ITypeSymbol , string > > _convertMethodsLookupByReturnType ;
3737 private readonly LambdaConverter _lambdaConverter ;
38- private readonly INamedTypeSymbol _vbBooleanTypeSymbol ;
3938 private readonly VisualBasicNullableExpressionsConverter _visualBasicNullableTypesConverter ;
4039 private readonly Dictionary < string , Stack < ( SyntaxNode Scope , string TempName ) > > _tempNameForAnonymousScope = new ( ) ;
4140 private readonly HashSet < string > _generatedNames = new ( StringComparer . OrdinalIgnoreCase ) ;
@@ -58,7 +57,6 @@ public ExpressionNodeVisitor(SemanticModel semanticModel,
5857 // If this isn't needed, the assembly with Conversions may not be referenced, so this must be done lazily
5958 _convertMethodsLookupByReturnType =
6059 new Lazy < IReadOnlyDictionary < ITypeSymbol , string > > ( ( ) => CreateConvertMethodsLookupByReturnType ( semanticModel ) ) ;
61- _vbBooleanTypeSymbol = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Boolean" ) ;
6260 }
6361
6462 private static IReadOnlyDictionary < ITypeSymbol , string > CreateConvertMethodsLookupByReturnType (
@@ -775,7 +773,7 @@ public override async Task<CSharpSyntaxNode> VisitBinaryConditionalExpression(VB
775773 public override async Task < CSharpSyntaxNode > VisitTernaryConditionalExpression ( VBasic . Syntax . TernaryConditionalExpressionSyntax node )
776774 {
777775 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 ) ;
779777
780778 var whenTrue = await node . WhenTrue . AcceptAsync < ExpressionSyntax > ( TriviaConvertingExpressionVisitor ) ;
781779 whenTrue = CommonConversions . TypeConversionAnalyzer . AddExplicitConversion ( node . WhenTrue , whenTrue ) ;
@@ -900,7 +898,7 @@ private async Task<CSharpSyntaxNode> ConvertBinaryExpressionAsync(VBasic.Syntax.
900898 omitConversion = lhsTypeInfo . Type . SpecialType == SpecialType . System_String ||
901899 rhsTypeInfo . Type . SpecialType == SpecialType . System_String ;
902900 if ( lhsTypeInfo . ConvertedType . SpecialType != SpecialType . System_String ) {
903- forceLhsTargetType = _semanticModel . Compilation . GetTypeByMetadataName ( "System. String" ) ;
901+ forceLhsTargetType = CommonConversions . KnownTypes . String ;
904902 }
905903 }
906904 }
@@ -938,6 +936,8 @@ private async Task<CSharpSyntaxNode> ConvertBinaryExpressionAsync(VBasic.Syntax.
938936 return node . Parent . IsKind ( VBasic . SyntaxKind . SimpleArgument ) ? exp : exp . AddParens ( ) ;
939937 }
940938
939+
940+
941941 private async Task < ExpressionSyntax > RewriteBinaryOperatorOrNullAsync ( VBSyntax . BinaryExpressionSyntax node ) =>
942942 await _operatorConverter . ConvertRewrittenBinaryOperatorOrNullAsync ( node , TriviaConvertingExpressionVisitor . IsWithinQuery ) ;
943943
@@ -1837,7 +1837,7 @@ private ArgumentSyntax CreateOptionalRefArg(IParameterSymbol p, RefKind refKind)
18371837
18381838 bool HasOptionalAttribute ( IParameterSymbol p )
18391839 {
1840- var optionalAttribute = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Runtime.InteropServices. OptionalAttribute" ) ;
1840+ var optionalAttribute = CommonConversions . KnownTypes . OptionalAttribute ;
18411841 if ( optionalAttribute == null ) {
18421842 return false ;
18431843 }
@@ -1849,7 +1849,7 @@ bool TryGetDefaultParameterValueAttributeValue(IParameterSymbol p, out object de
18491849 {
18501850 defaultValue = null ;
18511851
1852- var defaultParameterValueAttribute = _semanticModel . Compilation . GetTypeByMetadataName ( "System.Runtime.InteropServices. DefaultParameterValueAttribute" ) ;
1852+ var defaultParameterValueAttribute = CommonConversions . KnownTypes . DefaultParameterValueAttribute ;
18531853 if ( defaultParameterValueAttribute == null ) {
18541854 return false ;
18551855 }
@@ -1941,7 +1941,7 @@ private ISymbol GetInvocationSymbol(SyntaxNode invocation)
19411941 ( VBSyntax . InvocationExpressionSyntax e ) => _semanticModel . GetSymbolInfo ( e ) . ExtractBestMatch < ISymbol > ( ) ,
19421942 ( VBSyntax . ObjectCreationExpressionSyntax e ) => _semanticModel . GetSymbolInfo ( e ) . ExtractBestMatch < ISymbol > ( ) ,
19431943 ( 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 ( ) ,
19451945 _ => throw new NotSupportedException ( ) ) ;
19461946 return symbol ;
19471947 }
0 commit comments