Slide 140
Slide 140 text
private static void AnalyzeAsyncMethod(SymbolAnalysisContext context)
{
var methodSymbol = (IMethodSymbol)context.Symbol;
if (!methodSymbol.IsAsync)
{
return;
}
if (methodSymbol.ReturnType.FullName() == "System.Threading.Tasks.Task")
{
var diagnostic = Diagnostic.Create(Rule01, methodSymbol.Locations[0], methodSymbol.ReturnType);
context.ReportDiagnostic(diagnostic);
return;
}
if (methodSymbol.ReturnType.FullName() == "System.Void")
{
var diagnostic = Diagnostic.Create(Rule02, methodSymbol.Locations[0], methodSymbol.ReturnType);
context.ReportDiagnostic(diagnostic);
}
}
private static void AnalyzeAsyncMethod(SymbolAnalysisContext context)
{
var methodSymbol = (IMethodSymbol)context.Symbol;
if (!methodSymbol.IsAsync)
{
return;
}
if (methodSymbol.ReturnType.FullName() == "System.Threading.Tasks.Task")
{
var diagnostic = Diagnostic.Create(Rule01, methodSymbol.Locations[0], methodSymbol.ReturnType);
context.ReportDiagnostic(diagnostic);
return;
}
}
変更前
private static readonly DiagnosticDescriptor Rule02 = new
DiagnosticDescriptor(
id: "BanAsyncTask0002",
title: "Banned void in async Method",
messageFormat: "Do not use '{0}' in async Method, Should use
UniTaskVoid",
category: "Naming",
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: "Type names should be all uppercase.");
✔変更後
System.Voidの使用をレポートする
ルールを追加
140