Skip to content

Commit 6411d1c

Browse files
committed
C#: Refactor operator call logic
Refactored to make it clear when `@operator.Symbol as IMethodSymbol` can be `null`.
1 parent e05bbb0 commit 6411d1c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ public void OperatorCall(ExpressionSyntax node)
119119
var @operator = cx.GetSymbolInfo(node);
120120
var method = @operator.Symbol as IMethodSymbol;
121121

122-
if (GetCallType(cx, node) == CallType.Dynamic)
122+
var callType = GetCallType(cx, node);
123+
if (callType == CallType.Dynamic)
123124
{
124125
UserOperator.OperatorSymbol(method.Name, out string operatorName);
125126
cx.Emit(Tuples.dynamic_member_name(this, operatorName));
126127
return;
127128
}
128129

129-
if (method != null)
130+
if (callType != CallType.None)
130131
cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
131132
}
132133

@@ -148,12 +149,9 @@ public static CallType GetCallType(Context cx, ExpressionSyntax node)
148149
{
149150
var @operator = cx.GetSymbolInfo(node);
150151

151-
if (@operator.Symbol != null)
152+
if (@operator.Symbol is IMethodSymbol method)
152153
{
153-
var method = @operator.Symbol as IMethodSymbol;
154-
155-
var containingSymbol = method.ContainingSymbol as ITypeSymbol;
156-
if (containingSymbol != null && containingSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Dynamic)
154+
if (method.ContainingSymbol is ITypeSymbol containingSymbol && containingSymbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Dynamic)
157155
{
158156
return CallType.Dynamic;
159157
}

0 commit comments

Comments
 (0)