本文整理汇总了C#中ISymbol.CreateDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.CreateDiagnostic方法的具体用法?C# ISymbol.CreateDiagnostic怎么用?C# ISymbol.CreateDiagnostic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.CreateDiagnostic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeCodeBlock
public void AnalyzeCodeBlock(SyntaxNode codeBlock, ISymbol ownerSymbol, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
if (IsEmptyFinalizer(codeBlock, semanticModel))
{
addDiagnostic(ownerSymbol.CreateDiagnostic(Rule));
}
}
示例2: AnalyzeSymbol
public void AnalyzeSymbol(ISymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
var methodSymbol = (IMethodSymbol)symbol;
if (methodSymbol == null)
{
return;
}
var dllImportData = methodSymbol.GetDllImportData();
if (dllImportData == null)
{
return;
}
var dllAttribute = methodSymbol.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Equals(this.dllImportType));
var defaultLocation = dllAttribute == null ? methodSymbol.Locations.FirstOrDefault() : GetAttributeLocation(dllAttribute);
// CA1401 - PInvoke methods should not be visible
if (methodSymbol.DeclaredAccessibility == Accessibility.Public || methodSymbol.DeclaredAccessibility == Accessibility.Protected)
{
addDiagnostic(symbol.CreateDiagnostic(RuleCA1401, methodSymbol.Name));
}
// CA2101 - Specify marshalling for PInvoke string arguments
if (dllImportData.BestFitMapping != false)
{
bool appliedCA2101ToMethod = false;
foreach (var parameter in methodSymbol.Parameters)
{
if (parameter.Type.SpecialType == SpecialType.System_String || parameter.Type.Equals(this.stringBuilderType))
{
var marshalAsAttribute = parameter.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Equals(this.marshalAsType));
var charSet = marshalAsAttribute == null
? dllImportData.CharacterSet
: MarshalingToCharSet(GetParameterMarshaling(marshalAsAttribute));
// only unicode marshaling is considered safe
if (charSet != CharSet.Unicode)
{
if (marshalAsAttribute != null)
{
// track the diagnostic on the [MarshalAs] attribute
var marshalAsLocation = GetAttributeLocation(marshalAsAttribute);
addDiagnostic(marshalAsLocation.CreateDiagnostic(RuleCA2101));
}
else if (!appliedCA2101ToMethod)
{
// track the diagnostic on the [DllImport] attribute
appliedCA2101ToMethod = true;
addDiagnostic(defaultLocation.CreateDiagnostic(RuleCA2101));
}
}
}
}
// only unicode marshaling is considered safe, but only check this if we haven't already flagged the attribute
if (!appliedCA2101ToMethod && dllImportData.CharacterSet != CharSet.Unicode &&
(methodSymbol.ReturnType.SpecialType == SpecialType.System_String || methodSymbol.ReturnType.Equals(this.stringBuilderType)))
{
addDiagnostic(defaultLocation.CreateDiagnostic(RuleCA2101));
}
}
}