-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSyntaxNodeAnalysisContextExtensions.cs
More file actions
28 lines (25 loc) · 1.2 KB
/
SyntaxNodeAnalysisContextExtensions.cs
File metadata and controls
28 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace ExhaustiveMatching.Analyzer.Enums.Semantics
{
public static class SyntaxNodeAnalysisContextExtensions
{
/// <summary>
/// Get the type of an expression.
/// </summary>
public static ITypeSymbol? GetExpressionType(
this SyntaxNodeAnalysisContext context,
ExpressionSyntax switchStatementExpression)
=> context.SemanticModel.GetTypeInfo(switchStatementExpression, context.CancellationToken).Type;
/// <summary>
/// Get the converted type of an expression.
/// </summary>
public static ITypeSymbol? GetExpressionConvertedType(
this SyntaxNodeAnalysisContext context,
ExpressionSyntax switchStatementExpression) =>
context.SemanticModel.GetTypeInfo(switchStatementExpression, context.CancellationToken).ConvertedType;
public static ISymbol? GetSymbol(this SyntaxNodeAnalysisContext context, ExpressionSyntax expression)
=> context.SemanticModel.GetSymbolInfo(expression, context.CancellationToken).Symbol;
}
}