in ClrHeapAllocationsAnalyzer/TypeConversionAllocationAnalyzer.cs [43:116]
protected override void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
var node = context.Node;
var semanticModel = context.SemanticModel;
var cancellationToken = context.CancellationToken;
Action<Diagnostic> reportDiagnostic = context.ReportDiagnostic;
string filePath = node.SyntaxTree.FilePath;
bool assignedToReadonlyFieldOrProperty =
(context.ContainingSymbol as IFieldSymbol)?.IsReadOnly == true ||
(context.ContainingSymbol as IPropertySymbol)?.IsReadOnly == true;
// this.fooObjCall(10);
// new myobject(10);
if (node is ArgumentSyntax)
{
ArgumentSyntaxCheck(node, semanticModel, assignedToReadonlyFieldOrProperty, reportDiagnostic, filePath, cancellationToken);
}
// object foo { get { return 0; } }
if (node is ReturnStatementSyntax)
{
ReturnStatementExpressionCheck(node, semanticModel, reportDiagnostic, filePath, cancellationToken);
return;
}
// yield return 0
if (node is YieldStatementSyntax)
{
YieldReturnStatementExpressionCheck(node, semanticModel, reportDiagnostic, filePath, cancellationToken);
return;
}
// object a = x ?? 0;
// var a = 10 as object;
if (node is BinaryExpressionSyntax)
{
BinaryExpressionCheck(node, semanticModel, assignedToReadonlyFieldOrProperty, reportDiagnostic, filePath, cancellationToken);
return;
}
// for (object i = 0;;)
if (node is EqualsValueClauseSyntax)
{
EqualsValueClauseCheck(node, semanticModel, assignedToReadonlyFieldOrProperty, reportDiagnostic, filePath, cancellationToken);
return;
}
// object = true ? 0 : obj
if (node is ConditionalExpressionSyntax)
{
ConditionalExpressionCheck(node, semanticModel, reportDiagnostic, filePath, cancellationToken);
return;
}
// string a = $"{1}";
if (node is InterpolationSyntax) {
InterpolationCheck(node, semanticModel, reportDiagnostic, filePath, cancellationToken);
return;
}
// var f = (object)
if (node is CastExpressionSyntax)
{
CastExpressionCheck(node, semanticModel, reportDiagnostic, filePath, cancellationToken);
return;
}
// object Foo => 1
if (node is ArrowExpressionClauseSyntax)
{
ArrowExpressionCheck(node, semanticModel, assignedToReadonlyFieldOrProperty, reportDiagnostic, filePath, cancellationToken);
return;
}
}