本文整理汇总了C#中SymbolAnalysisContext.IsGeneratedOrNonUserCode方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolAnalysisContext.IsGeneratedOrNonUserCode方法的具体用法?C# SymbolAnalysisContext.IsGeneratedOrNonUserCode怎么用?C# SymbolAnalysisContext.IsGeneratedOrNonUserCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolAnalysisContext
的用法示例。
在下文中一共展示了SymbolAnalysisContext.IsGeneratedOrNonUserCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassSealedCheck
private void ClassSealedCheck(SymbolAnalysisContext context)
{
// I don't care about generated code.
if (context.IsGeneratedOrNonUserCode())
{
return;
}
INamedTypeSymbol symbol = context.Symbol as INamedTypeSymbol;
// It's all about the class, no structure.
if ((!symbol.IsValueType) && (!symbol.IsSealed) && (!symbol.IsStatic) && (!symbol.IsAbstract))
{
var diagnostic = Diagnostic.Create(Rule, symbol.Locations[0], symbol.Name);
context.ReportDiagnostic(diagnostic);
}
}
示例2: AnalyzeMethod
private static void AnalyzeMethod(SymbolAnalysisContext context)
{
// I don't care about generated code.
if (context.IsGeneratedOrNonUserCode())
{
return;
}
// Look for a return of Task<T> or Task
// Look at method name
// If doesn't end in Async, report diagnostic
IMethodSymbol methodSymbol = (IMethodSymbol)context.Symbol;
ITypeSymbol returnTypeSymbol = methodSymbol.ReturnType;
// Make sure we are dealing with the true system type.
String assemblyName = returnTypeSymbol?.ContainingAssembly?.Identity?.Name;
if ((assemblyName != null) && (!assemblyName.Contains("mscorlib")))
{
return;
}
// Account for both Task and Task<T>
if (!returnTypeSymbol.Name.StartsWith("Task"))
{
return;
}
// Now look at the method name from the code.
if (methodSymbol.Name.ToString().EndsWith("Async"))
{
return;
}
// If here, we found an async method that does not end with "Async"
var diagnostic = Diagnostic.Create(Rule,
methodSymbol.Locations[0],
methodSymbol.Name);
context.ReportDiagnostic(diagnostic);
}
示例3: AnalyzeSuppressMessage
private void AnalyzeSuppressMessage(SymbolAnalysisContext context)
{
if (context.IsGeneratedOrNonUserCode())
{
return;
}
// Look at the attributes for SuppressMessage.
var attributes = context.Symbol.GetAttributes();
for (Int32 i = 0; i < attributes.Count(); i++)
{
if (attributes[i].AttributeClass.Name.Equals("SuppressMessageAttribute"))
{
Boolean hasJustification = false;
// Look for the named parameters for Justification and if it doesn't exist,
// is empty, or has the text <Pending>, report the error.
var namedParams = attributes[i].NamedArguments;
for (Int32 j = 0; j < namedParams.Count(); j++)
{
if (namedParams[j].Key.Equals("Justification"))
{
String textValue = namedParams[j].Value.Value.ToString();
if ((String.IsNullOrEmpty(textValue) || (String.Equals(textValue, Resources.PendingText))))
{
var diagnostic = Diagnostic.Create(Rule, context.Symbol.Locations[0], context.Symbol.Name);
context.ReportDiagnostic(diagnostic);
}
hasJustification = true;
}
}
if (!hasJustification)
{
var diagnostic = Diagnostic.Create(Rule, context.Symbol.Locations[0], context.Symbol.Name);
context.ReportDiagnostic(diagnostic);
}
}
}
}
开发者ID:vuder,项目名称:Wintellect.Analyzers,代码行数:40,代码来源:SuppressionMessageMissingJustificationAnalyzer.cs