本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticAnalyzer.ToString方法的具体用法?C# DiagnosticAnalyzer.ToString怎么用?C# DiagnosticAnalyzer.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer
的用法示例。
在下文中一共展示了DiagnosticAnalyzer.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAnalyzerRules
private Rules GetAnalyzerRules(DiagnosticAnalyzer analyzer)
{
// For info on SonarQube rules see http://docs.sonarqube.org/display/SONAR/Rules
Rules rules = new Rules();
foreach (DiagnosticDescriptor diagnostic in analyzer.SupportedDiagnostics)
{
if (String.IsNullOrWhiteSpace(diagnostic.Id))
{
logger.LogWarning(UIResources.RuleGen_EmptyKey, analyzer.ToString());
continue;
}
Rule newRule = new Rule();
newRule.Key = diagnostic.Id;
newRule.InternalKey = diagnostic.Id;
newRule.Description = GetDescriptionAsRawHtml(diagnostic);
newRule.Name = diagnostic.Title.ToString(CultureInfo.InvariantCulture);
newRule.Severity = GetSonarQubeSeverity(diagnostic.DefaultSeverity);
// Rule XML properties that don't have an obvious Diagnostic equivalent:
newRule.Cardinality = Cardinality;
newRule.Status = Status;
// Diagnostic properties that don't have an obvious Rule xml equivalent:
// diagnostic.Category
// diagnostic.IsEnabledByDefault
// diagnostic.MessageFormat
/* Remark: Custom tags are used so that Visual Studio handles diagnostics and are not equivalent to SonarQube's tags
*
* http://stackoverflow.com/questions/24257222/relevance-of-new-parameters-for-diagnosticdescriptor-constructor
* customTags is a general way to mark that a diagnostic should be treated or displayed somewhat
* different than normal diagnostics. The "unnecessary" tag means that in the IDE we fade out the span
* that the diagnostic applies to: this is how we fade out unnecessary usings or casts or such in the IDE.
* In some fancy scenarios you might want to define your own, but for the most part you'll either leave that empty
* or pass Unnecessary if you want the different UI handling.
* The EditAndContinue tag is for errors that are created if an edit-and-continue edit can't be applied
* (which are also displayed somewhat differently)...that's just for us (n.b. Roslyn) to use.
*/
rules.Add(newRule);
}
return rules;
}
示例2: CreateAnalyzerExceptionDiagnostic
/// <summary>
/// Create a diagnostic for exception thrown by the given analyzer.
/// </summary>
/// <remarks>
/// Keep this method in sync with "AnalyzerExecutor.CreateAnalyzerExceptionDiagnostic".
/// </remarks>
internal static Diagnostic CreateAnalyzerExceptionDiagnostic(DiagnosticAnalyzer analyzer, Exception e)
{
var analyzerName = analyzer.ToString();
// TODO: It is not ideal to create a new descriptor per analyzer exception diagnostic instance.
// However, until we add a LongMessage field to the Diagnostic, we are forced to park the instance specific description onto the Descriptor's Description field.
// This requires us to create a new DiagnosticDescriptor instance per diagnostic instance.
var descriptor = new DiagnosticDescriptor(AnalyzerExceptionDiagnosticId,
title: FeaturesResources.User_Diagnostic_Analyzer_Failure,
messageFormat: FeaturesResources.Analyzer_0_threw_an_exception_of_type_1_with_message_2,
description: string.Format(FeaturesResources.Analyzer_0_threw_the_following_exception_colon_1, analyzerName, e.CreateDiagnosticDescription()),
category: AnalyzerExceptionDiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.AnalyzerException);
return Diagnostic.Create(descriptor, Location.None, analyzerName, e.GetType(), e.Message);
}
示例3: CreateAnalyzerExceptionDiagnostic
/// <summary>
/// Create a diagnostic for exception thrown by the given analyzer.
/// </summary>
/// <remarks>
/// Keep this method in sync with "AnalyzerExecutor.CreateAnalyzerExceptionDiagnostic".
/// </remarks>
internal static Diagnostic CreateAnalyzerExceptionDiagnostic(DiagnosticAnalyzer analyzer, Exception e)
{
var analyzerName = analyzer.ToString();
// TODO: It is not ideal to create a new descriptor per analyzer exception diagnostic instance.
// However, until we add a LongMessage field to the Diagnostic, we are forced to park the instance specific description onto the Descriptor's Description field.
// This requires us to create a new DiagnosticDescriptor instance per diagnostic instance.
var descriptor = new DiagnosticDescriptor(AnalyzerExceptionDiagnosticId,
title: AnalyzerDriverResources.AnalyzerFailure,
messageFormat: AnalyzerDriverResources.AnalyzerThrows,
description: string.Format(AnalyzerDriverResources.AnalyzerThrowsDescription, analyzerName, e.ToString()),
category: AnalyzerExceptionDiagnosticCategory,
defaultSeverity: DiagnosticSeverity.Info,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.AnalyzerException);
return Diagnostic.Create(descriptor, Location.None, analyzerName, e.GetType(), e.Message);
}