本文整理汇总了C#中IMethodSymbol.CreateDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodSymbol.CreateDiagnostic方法的具体用法?C# IMethodSymbol.CreateDiagnostic怎么用?C# IMethodSymbol.CreateDiagnostic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethodSymbol
的用法示例。
在下文中一共展示了IMethodSymbol.CreateDiagnostic方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckDisposeImplementationRule
/// <summary>
/// Checks rule: Modify {0} so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance ('this' or 'Me' in Visual Basic), and then returns.
/// </summary>
private void CheckDisposeImplementationRule(IMethodSymbol method, INamedTypeSymbol type, ImmutableArray<IOperation> operationBlocks, OperationBlockAnalysisContext context)
{
var validator = new DisposeImplementationValidator(_suppressFinalizeMethod, type);
if (!validator.Validate(operationBlocks))
{
context.ReportDiagnostic(method.CreateDiagnostic(DisposeImplementationRule, $"{type.Name}.{method.Name}"));
}
}
示例2: CheckDisposeBoolSignatureRule
// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Ensure that {0} is declared as protected, virtual, and unsealed.
/// </summary>
private static void CheckDisposeBoolSignatureRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.DeclaredAccessibility != Accessibility.Protected ||
!(method.IsVirtual || method.IsAbstract || method.IsOverride) || method.IsSealed)
{
context.ReportDiagnostic(method.CreateDiagnostic(DisposeBoolSignatureRule, $"{type.Name}.{method.Name}"));
}
}
示例3: CheckRenameDisposeRule
// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Rename {0} to 'Dispose' and ensure that it is declared as public and sealed.
/// </summary>
private static void CheckRenameDisposeRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.Name != DisposeMethodName)
{
context.ReportDiagnostic(method.CreateDiagnostic(RenameDisposeRule, $"{type.Name}.{method.Name}"));
}
}
示例4: CheckDisposeOverrideRule
// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Remove {0}, override Dispose(bool disposing), and put the dispose logic in the code path where 'disposing' is true.
/// </summary>
private void CheckDisposeOverrideRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (method.MethodKind == MethodKind.Ordinary && method.IsOverride && method.ReturnsVoid && method.Parameters.Length == 0)
{
bool isDisposeOverride = false;
for (IMethodSymbol m = method.OverriddenMethod; m != null; m = m.OverriddenMethod)
{
if (m == FindDisposeMethod(m.ContainingType))
{
isDisposeOverride = true;
break;
}
}
if (isDisposeOverride)
{
context.ReportDiagnostic(method.CreateDiagnostic(DisposeOverrideRule, $"{type.Name}.{method.Name}"));
}
}
}
示例5: CheckDisposeSignatureRule
// CA1801: Remove unused parameters.
// TODO: Remove the below suppression once Roslyn bug https://github.com/dotnet/roslyn/issues/8884 is fixed.
#pragma warning disable CA1801
/// <summary>
/// Checks rule: Ensure that {0} is declared as public and sealed.
/// </summary>
private static void CheckDisposeSignatureRule(IMethodSymbol method, INamedTypeSymbol type, SymbolAnalysisContext context)
#pragma warning restore CA1801
{
if (!method.IsPublic() ||
method.IsAbstract || method.IsVirtual || (method.IsOverride && !method.IsSealed))
{
context.ReportDiagnostic(method.CreateDiagnostic(DisposeSignatureRule, $"{type.Name}.{method.Name}"));
}
}