本文整理汇总了C#中Diagnostic.WithReportDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# Diagnostic.WithReportDiagnostic方法的具体用法?C# Diagnostic.WithReportDiagnostic怎么用?C# Diagnostic.WithReportDiagnostic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diagnostic
的用法示例。
在下文中一共展示了Diagnostic.WithReportDiagnostic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Filter
/// <summary>
/// Modifies an input <see cref="Diagnostic"/> per the given options. For example, the
/// severity may be escalated, or the <see cref="Diagnostic"/> may be filtered out entirely
/// (by returning null).
/// </summary>
/// <param name="d">The input diagnostic</param>
/// <param name="warningLevelOption">The maximum warning level to allow. Diagnostics with a higher warning level will be filtered out.</param>
/// <param name="generalDiagnosticOption">How warning diagnostics should be reported</param>
/// <param name="specificDiagnosticOptions">How specific diagnostics should be reported</param>
/// <returns>A diagnostic updated to reflect the options, or null if it has been filtered out</returns>
public static Diagnostic Filter(Diagnostic d, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary<string, ReportDiagnostic> specificDiagnosticOptions)
{
if (d == null)
{
return d;
}
else if (d.IsNotConfigurable())
{
if (d.IsEnabledByDefault)
{
// Enabled NotConfigurable should always be reported as it is.
return d;
}
else
{
// Disabled NotConfigurable should never be reported.
return null;
}
}
else if (d.Severity == InternalDiagnosticSeverity.Void)
{
return null;
}
//In the native compiler, all warnings originating from alink.dll were issued
//under the id WRN_ALinkWarn - 1607. If a customer used nowarn:1607 they would get
//none of those warnings. In Roslyn, we've given each of these warnings their
//own number, so that they may be configured independently. To preserve compatibility
//if a user has specifically configured 1607 and we are reporting one of the alink warnings, use
//the configuration specified for 1607. As implemented, this could result in customers
//specifying warnaserror:1607 and getting a message saying "warning as error CS8012..."
//We don't permit configuring 1607 and independently configuring the new warnings.
ReportDiagnostic reportAction;
if (s_alinkWarnings.Contains((ErrorCode)d.Code) &&
specificDiagnosticOptions.Keys.Contains(CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn)))
{
reportAction = GetDiagnosticReport(ErrorFacts.GetSeverity(ErrorCode.WRN_ALinkWarn),
d.IsEnabledByDefault,
CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn),
ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn),
d.Location as Location,
d.Category,
warningLevelOption,
generalDiagnosticOption,
specificDiagnosticOptions);
}
else
{
reportAction = GetDiagnosticReport(d.Severity, d.IsEnabledByDefault, d.Id, d.WarningLevel, d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions);
}
return d.WithReportDiagnostic(reportAction);
}
示例2: Filter
/// <summary>
/// Modifies an input <see cref="Diagnostic"/> per the given options. For example, the
/// severity may be escalated, or the <see cref="Diagnostic"/> may be filtered out entirely
/// (by returning null).
/// </summary>
/// <param name="d">The input diagnostic</param>
/// <param name="warningLevelOption">The maximum warning level to allow. Diagnostics with a higher warning level will be filtered out.</param>
/// <param name="generalDiagnosticOption">How warning diagnostics should be reported</param>
/// <param name="specificDiagnosticOptions">How specific diagnostics should be reported</param>
/// <returns>A diagnostic updated to reflect the options, or null if it has been filtered out</returns>
public static Diagnostic Filter(Diagnostic d, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary<string, ReportDiagnostic> specificDiagnosticOptions)
{
if (d == null) return d;
switch (d.Severity)
{
case DiagnosticSeverity.Error:
// If it is a compiler error, keep it as it is.
// TODO: We currently use .Category to detect whether the diagnostic is a compiler diagnostic.
// Perhaps there should be a stronger way of checking this that avoids the possibility of an
// inadvertent clash for some custom diagnostic that happens to use the same category string.
if (d.Category == Diagnostic.CompilerDiagnosticCategory)
{
return d;
}
break;
case InternalDiagnosticSeverity.Void:
return null;
default:
break;
}
//In the native compiler, all warnings originating from alink.dll were issued
//under the id WRN_ALinkWarn - 1607. If a customer used nowarn:1607 they would get
//none of those warnings. In Roslyn, we've given each of these warnings their
//own number, so that they may be configured independently. To preserve compatibility
//if a user has specifically configured 1607 and we are reporting one of the alink warnings, use
//the configuration specified for 1607. As implemented, this could result in customers
//specifying warnaserror:1607 and getting a message saying "warning as error CS8012..."
//We don't permit configuring 1607 and independently configuring the new warnings.
ReportDiagnostic reportAction;
if (AlinkWarnings.Contains((ErrorCode)d.Code) &&
specificDiagnosticOptions.Keys.Contains(CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn)))
{
reportAction = GetDiagnosticReport(ErrorFacts.GetSeverity(ErrorCode.WRN_ALinkWarn),
d.IsEnabledByDefault,
CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn),
ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn),
d.Location as Location,
d.Category,
warningLevelOption,
generalDiagnosticOption,
specificDiagnosticOptions);
}
else
{
reportAction = GetDiagnosticReport(d.Severity, d.IsEnabledByDefault, d.Id, d.WarningLevel, d.Location as Location, d.Category, warningLevelOption, generalDiagnosticOption, specificDiagnosticOptions);
}
return d.WithReportDiagnostic(reportAction);
}
示例3: FilterDiagnostic
private static Diagnostic FilterDiagnostic(Diagnostic d, CSharpCompilationOptions options)
{
if (d == null) return d;
switch (d.Severity)
{
case DiagnosticSeverity.Error:
return d;
case InternalDiagnosticSeverity.Void:
return null;
default:
break;
}
//In the native compiler, all warnings originating from alink.dll were issued
//under the id WRN_ALinkWarn - 1607. If a customer used nowarn:1607 they would get
//none of those warnings. In Roslyn, we've given each of these warnings their
//own number, so that they may be configured independently. To preserve compatibility
//if a user has specifically configured 1607 and we are reporting one of the alink warnings, use
//the configuration specified for 1607. As implemented, this could result in customers
//specifying warnaserror:1607 and getting a message saying "warning as error CS8012..."
//We don't permit configuring 1607 and independently configuring the new warnings.
ReportDiagnostic reportAction;
if (AlinkWarnings.Contains((ErrorCode)d.Code) &&
options.SpecificDiagnosticOptions.Keys.Contains(CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn)))
{
reportAction = GetDiagnosticReport(ErrorFacts.GetSeverity(ErrorCode.WRN_ALinkWarn),
d.IsEnabledByDefault,
CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_ALinkWarn),
ErrorFacts.GetWarningLevel(ErrorCode.WRN_ALinkWarn),
d.Location as Location,
options,
d.Category);
}
else
{
reportAction = GetDiagnosticReport(d.Severity, d.IsEnabledByDefault, d.Id, d.WarningLevel, d.Location as Location, options, d.Category);
}
return d.WithReportDiagnostic(reportAction);
}