本文整理汇总了C#中DiagnosticSeverity类的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticSeverity类的具体用法?C# DiagnosticSeverity怎么用?C# DiagnosticSeverity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiagnosticSeverity类属于命名空间,在下文中一共展示了DiagnosticSeverity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDescriptorWithId
private DiagnosticDescriptor CreateDescriptorWithId(string id, LocalizableString title, LocalizableString message, DiagnosticSeverity severity, params string[] customTags)
=> new DiagnosticDescriptor(
id, title, message,
DiagnosticCategory.Style,
severity,
isEnabledByDefault: true,
customTags: customTags);
示例2: SimpleDiagnostic
private SimpleDiagnostic(
DiagnosticDescriptor descriptor,
DiagnosticSeverity severity,
int warningLevel,
Location location,
IEnumerable<Location> additionalLocations,
object[] messageArgs)
{
if ((warningLevel == 0 && severity != DiagnosticSeverity.Error) ||
(warningLevel != 0 && severity == DiagnosticSeverity.Error))
{
throw new ArgumentException(nameof(warningLevel));
}
if(descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
_descriptor = descriptor;
_severity = severity;
_warningLevel = warningLevel;
_location = location ?? Location.None;
_additionalLocations = additionalLocations == null ? SpecializedCollections.EmptyReadOnlyList<Location>() : additionalLocations.ToImmutableArray();
_messageArgs = messageArgs ?? SpecializedCollections.EmptyArray<object>();
}
示例3: Diagnostic
public readonly TextSpan TextSpan; //opt
#endregion Fields
#region Constructors
public Diagnostic(DiagnosticSeverity severity, int code, string message, TextSpan textSpan)
{
Severity = severity;
Code = code;
Message = message;
TextSpan = textSpan;
}
示例4: DiagnosticResult
/// <summary>
/// インスタンスを初期化します。
/// </summary>
/// <param name="id">解析したルールの識別子</param>
/// <param name="message">解析結果のメッセージ</param>
/// <param name="severity">解析したルールの重大度</param>
/// <param name="locations">解析結果が示すソースコードの位置</param>
public DiagnosticResult(string id, string message, DiagnosticSeverity? severity, params DiagnosticResultLocation[] locations)
{
Id = id;
Message = message;
Severity = severity;
Locations = locations ?? new DiagnosticResultLocation[0];
}
示例5: DiagnosticData
public DiagnosticData(
string id,
string category,
string message,
string enuMessageForBingSearch,
DiagnosticSeverity severity,
bool isEnabledByDefault,
int warningLevel,
Workspace workspace,
ProjectId projectId,
DocumentId documentId = null,
TextSpan? span = null,
string originalFilePath = null,
int originalStartLine = 0,
int originalStartColumn = 0,
int originalEndLine = 0,
int originalEndColumn = 0,
string title = null,
string description = null,
string helpLink = null) :
this(
id, category, message, enuMessageForBingSearch,
severity, severity, isEnabledByDefault, warningLevel,
ImmutableArray<string>.Empty, ImmutableDictionary<string, string>.Empty,
workspace, projectId, documentId, span,
null, originalStartLine, originalStartColumn, originalEndLine, originalEndColumn,
originalFilePath, originalStartLine, originalStartColumn, originalEndLine, originalEndColumn,
title, description, helpLink)
{
}
示例6: SimpleDiagnostic
private SimpleDiagnostic(
DiagnosticDescriptor descriptor,
DiagnosticSeverity severity,
int warningLevel,
Location location,
IEnumerable<Location> additionalLocations,
object[] messageArgs,
ImmutableDictionary<string, string> properties,
bool isSuppressed)
{
if ((warningLevel == 0 && severity != DiagnosticSeverity.Error) ||
(warningLevel != 0 && severity == DiagnosticSeverity.Error))
{
throw new ArgumentException(nameof(warningLevel));
}
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
_descriptor = descriptor;
_severity = severity;
_warningLevel = warningLevel;
_location = location ?? Location.None;
_additionalLocations = additionalLocations?.ToImmutableArray() ?? SpecializedCollections.EmptyReadOnlyList<Location>();
_messageArgs = messageArgs ?? Array.Empty<object>();
_properties = properties ?? ImmutableDictionary<string, string>.Empty;
_isSuppressed = isSuppressed;
}
示例7: SimpleDiagnostic
internal SimpleDiagnostic(string id, string category, string message, DiagnosticSeverity severity, bool isEnabledByDefault,
int warningLevel, bool isWarningAsError, Location location,
IEnumerable<Location> additionalLocations)
{
if (isWarningAsError && severity != DiagnosticSeverity.Warning)
{
throw new ArgumentException("isWarningAsError");
}
if ((warningLevel == 0 && severity == DiagnosticSeverity.Warning) ||
(warningLevel != 0 && severity != DiagnosticSeverity.Warning))
{
throw new ArgumentException("warningLevel");
}
this.id = id;
this.category = category;
this.message = message;
this.severity = severity;
this.isEnabledByDefault = isEnabledByDefault;
this.warningLevel = warningLevel;
this.isWarningAsError = isWarningAsError;
this.location = location;
this.additionalLocations = additionalLocations == null ? SpecializedCollections.EmptyReadOnlyList<Location>() : additionalLocations.ToImmutableArray();
}
示例8: TestParseEditorConfigCodeStyleOption
static void TestParseEditorConfigCodeStyleOption(string args, bool isEnabled, DiagnosticSeverity severity)
{
var notificationOption = NotificationOption.None;
switch (severity)
{
case DiagnosticSeverity.Hidden:
notificationOption = NotificationOption.None;
break;
case DiagnosticSeverity.Info:
notificationOption = NotificationOption.Suggestion;
break;
case DiagnosticSeverity.Warning:
notificationOption = NotificationOption.Warning;
break;
case DiagnosticSeverity.Error:
notificationOption = NotificationOption.Error;
break;
}
var codeStyleOption = new CodeStyleOption<bool>(value: isEnabled, notification: notificationOption);
var result = CodeStyleHelpers.ParseEditorConfigCodeStyleOption(args);
Assert.True(result.Value == isEnabled,
$"Expected {nameof(isEnabled)} to be {isEnabled}, was {result.Value}");
Assert.True(result.Notification.Value == severity,
$"Expected {nameof(severity)} to be {severity}, was {result.Notification.Value}");
}
示例9: AnalyzerDetails
public AnalyzerDetails(string className,
AnalyzerCategoryDetails category,
DefaultState defaultState,
DiagnosticSeverity severity,
string titleResourceName,
string descriptionResourceName,
string messageFormatResourceName,
IList<Type> suppressionAttributes)
{
var decomposedDetails = DecomposeDetailsFromClassName(className);
var code = decomposedDetails.Item1;
Name = decomposedDetails.Item2;
NameWithCode = $"{decomposedDetails.Item3} - {Name}";
Category = category;
_defaultState = defaultState;
Severity = severity;
SuppressionAttributes = suppressionAttributes;
Title = LocalizableStringFactory.LocalizableResourceString(titleResourceName);
Description = LocalizableStringFactory.LocalizableResourceString(descriptionResourceName);
MessageFormat = LocalizableStringFactory.LocalizableResourceString(messageFormatResourceName);
DiagnosticId = Title.ToString().Replace("-", "");
if (Title.ToString() != code)
{
throw new ArgumentException([email protected]"Title resource value isn't of the correct format: should be {code}",
nameof(titleResourceName));
}
}
示例10: GetMessagePrefix
// Given a message identifier (e.g., CS0219), severity, warning as error and a culture,
// get the entire prefix (e.g., "error CS0219: Warning as Error:" for C#) used on error messages.
public override string GetMessagePrefix(string id, DiagnosticSeverity severity, bool isWarningAsError, CultureInfo culture)
{
return String.Format(culture, "{0} {1}{2}",
severity == DiagnosticSeverity.Error || isWarningAsError ? "error" : "warning",
id,
isWarningAsError ? ErrorFacts.GetMessage(MessageID.IDS_WarnAsError, culture) : "");
}
示例11: EnforcementLevel
public EnforcementLevel(DiagnosticSeverity severity)
{
Value = severity;
switch (severity)
{
case DiagnosticSeverity.Hidden:
Name = "None";
Moniker = KnownMonikers.None;
return;
case DiagnosticSeverity.Info:
Name = "Suggestion";
Moniker = KnownMonikers.StatusInformation;
return;
case DiagnosticSeverity.Warning:
Name = "Warning";
Moniker = KnownMonikers.StatusWarning;
return;
case DiagnosticSeverity.Error:
Name = "Error";
Moniker = KnownMonikers.StatusError;
return;
default:
throw new ArgumentException("Unexpected DiagnosticSeverity", nameof(severity));
}
}
示例12: GetDiagnosticReport
// Take a warning and return the final deposition of the given warning,
// based on both command line options and pragmas.
// If you update this method, also update DiagnosticItemSource.GetEffectiveSeverity.
internal static ReportDiagnostic GetDiagnosticReport(DiagnosticSeverity severity, bool isEnabledByDefault, string id, int diagnosticWarningLevel, Location location, string category, int warningLevelOption, ReportDiagnostic generalDiagnosticOption, IDictionary<string, ReportDiagnostic> specificDiagnosticOptions)
{
// Read options (e.g., /nowarn or /warnaserror)
ReportDiagnostic report = ReportDiagnostic.Default;
var isSpecified = specificDiagnosticOptions.TryGetValue(id, out report);
if (!isSpecified)
{
report = isEnabledByDefault ? ReportDiagnostic.Default : ReportDiagnostic.Suppress;
}
// Compute if the reporting should be suppressed.
if (diagnosticWarningLevel > warningLevelOption // honor the warning level
|| report == ReportDiagnostic.Suppress) // check options (/nowarn)
{
return ReportDiagnostic.Suppress;
}
// If location is available, check out pragmas
if (location != null &&
location.SourceTree != null &&
((SyntaxTree)location.SourceTree).GetPragmaDirectiveWarningState(id, location.SourceSpan.Start) == ReportDiagnostic.Suppress)
{
return ReportDiagnostic.Suppress;
}
// Unless specific warning options are defined (/warnaserror[+|-]:<n> or /nowarn:<n>,
// follow the global option (/warnaserror[+|-] or /nowarn).
if (report == ReportDiagnostic.Default)
{
switch (generalDiagnosticOption)
{
case ReportDiagnostic.Error:
// If we've been asked to do warn-as-error then don't raise severity for anything below warning (info or hidden).
if (severity == DiagnosticSeverity.Warning)
{
// In the case where /warnaserror+ is followed by /warnaserror-:<n> on the command line,
// do not promote the warning specified in <n> to an error.
if (!isSpecified && (report == ReportDiagnostic.Default))
{
return ReportDiagnostic.Error;
}
}
break;
case ReportDiagnostic.Suppress:
// When doing suppress-all-warnings, don't lower severity for anything other than warning and info.
// We shouldn't suppress hidden diagnostics here because then features that use hidden diagnostics to
// display a lightbulb would stop working if someone has suppress-all-warnings (/nowarn) specified in their project.
if (severity == DiagnosticSeverity.Warning || severity == DiagnosticSeverity.Info)
{
return ReportDiagnostic.Suppress;
}
break;
default:
break;
}
}
return report;
}
示例13: Result
public Result (TextSpan region, string message, DiagnosticSeverity level, IssueMarker inspectionMark, bool underline = true)
{
this.Region = region;
this.Message = message;
this.Level = level;
this.InspectionMark = inspectionMark;
this.Underline = underline;
}
示例14: CreateDiagnosticDescriptor
private DiagnosticDescriptor CreateDiagnosticDescriptor(DiagnosticSeverity severity) =>
new DiagnosticDescriptor(
_diagnosticId,
_title,
_message,
DiagnosticCategory.Style,
severity,
isEnabledByDefault: true);
示例15: DiagnosticDescriptor
/// <summary>
/// Create a DiagnosticDescriptor, which provides description about a <see cref="Diagnostic"/>.
/// </summary>
/// <param name="id">A unique identifier for the diagnostic. For example, code analysis diagnostic ID "CA1001".</param>
/// <param name="description">A short localizable description of the diagnostic. For example, for CA1001: "Types that own disposable fields should be disposable".</param>
/// <param name="messageFormat">A localizable format message string, which can be passed as the first argument to <see cref="M:System.String.Format"/> when creating the diagnostic message with this descriptor.
/// For example, for CA1001: "Implement IDisposable on '{0}' because it creates members of the following IDisposable types: '{1}'."</param>
/// <param name="category">The category of the diagnostic (like Design, Naming etc.). For example, for CA1001: "Microsoft.Design".</param>
/// <param name="defaultSeverity">Default severity of the diagnostic.</param>
public DiagnosticDescriptor(string id, string description, string messageFormat, string category, DiagnosticSeverity defaultSeverity)
{
this.Id = id;
this.Description = description;
this.Category = category;
this.MessageFormat = messageFormat;
this.DefaultSeverity = defaultSeverity;
}