本文整理汇总了C#中INamedTypeSymbol.CreateDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.CreateDiagnostic方法的具体用法?C# INamedTypeSymbol.CreateDiagnostic怎么用?C# INamedTypeSymbol.CreateDiagnostic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INamedTypeSymbol
的用法示例。
在下文中一共展示了INamedTypeSymbol.CreateDiagnostic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
{
addDiagnostic(symbol.CreateDiagnostic(Rule));
}
}
示例2: AnalyzeSymbol
private void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic)
{
if (symbol.GetMembers().Any(member => IsDllImport(member)) && !IsTypeNamedCorrectly(symbol.Name))
{
addDiagnostic(symbol.CreateDiagnostic(Rule));
}
}
示例3: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, Action<Diagnostic> addDiagnostic)
{
if (namedTypeSymbol.IsValueType && namedTypeSymbol.DoesOverrideEquals() && !IsEqualityOperatorImplemented(namedTypeSymbol))
{
addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule));
}
}
示例4: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
if (namedTypeSymbol.IsValueType && IsOverridesEquals(namedTypeSymbol) && !IsEqualityOperatorImplemented(namedTypeSymbol))
{
addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule));
}
}
示例5: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol namedType, INamedTypeSymbol attributeType, Action<Diagnostic> addDiagnostic)
{
if (namedType.IsAbstract || namedType.IsSealed || !namedType.GetBaseTypesAndThis().Contains(attributeType))
{
return;
}
// Non-sealed non-abstract attribute type.
addDiagnostic(namedType.CreateDiagnostic(Rule));
}
示例6: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol namedType, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
if (namedType.IsAbstract || namedType.IsSealed || !namedType.IsAttribute())
{
return;
}
// Non-sealed non-abstract attribute type.
addDiagnostic(namedType.CreateDiagnostic(Rule));
}
示例7: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol symbol, INamedTypeSymbol attributeType, INamedTypeSymbol attributeUsageAttributeType, Action<Diagnostic> addDiagnostic)
{
if (symbol.IsAbstract || !symbol.GetBaseTypesAndThis().Contains(attributeType))
{
return;
}
bool hasAttributeUsageAttribute = symbol.GetAttributes().Any(attribute => attribute.AttributeClass.Equals(attributeUsageAttributeType));
if (!hasAttributeUsageAttribute)
{
addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
}
}
示例8: AnalyzeSymbol
protected override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
// TODO: should this be restricted to class types?
// static holder types are not already static/sealed and must be public or protected
if (!symbol.IsStatic && !symbol.IsSealed
&& (symbol.DeclaredAccessibility == Accessibility.Public || symbol.DeclaredAccessibility == Accessibility.Protected))
{
// only get the explicitly declared members
var allMembers = symbol.GetMembers().Where(member => !member.IsImplicitlyDeclared);
if (!allMembers.Any())
{
return;
}
// to be a static holder type, all members must be static and not operator overloads
if (allMembers.All(member => (member.IsStatic || symbol.InstanceConstructors.Contains(member)) && !IsUserdefinedOperator(member)))
{
// Has a default constructor that is implicitly defined
if (!symbol.InstanceConstructors.IsEmpty)
{
if (symbol.InstanceConstructors.Count() == 1 &&
symbol.InstanceConstructors.First().Parameters.IsEmpty)
{
// If there is just the default constructor, we can make the type static.
// Produce Diagnostic CA1052
addDiagnostic(symbol.CreateDiagnostic(CA1052Rule, symbol.Name));
}
else if (symbol.InstanceConstructors.Count() > 0)
{
// If there are explicitly defined constructors then we cannot make the type static instead just show a diagnostic.
// Instead we show a Diagnostic CA1053 with no fix
addDiagnostic(symbol.CreateDiagnostic(CA1053Rule, symbol.Name));
}
}
}
}
}
示例9: AnalyzeSymbol
protected override void AnalyzeSymbol(
INamedTypeSymbol symbol,
Compilation compilation,
Action<Diagnostic> addDiagnostic,
AnalyzerOptions options,
CancellationToken cancellationToken)
{
if (!symbol.IsStatic
&& (symbol.IsPublic() || symbol.IsProtected())
&& symbol.IsStaticHolderType())
{
addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
}
}
示例10: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol symbol, INamedTypeSymbol disposableType, Action<Diagnostic> addDiagnostic)
{
if (!symbol.AllInterfaces.Contains(disposableType))
{
var disposableFields = from member in symbol.GetMembers()
where member.Kind == SymbolKind.Field && !member.IsStatic
let field = member as IFieldSymbol
where field.Type != null && field.Type.AllInterfaces.Contains(disposableType)
select field;
if (disposableFields.Any())
{
addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
}
}
}
示例11: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
if (symbol.IsAbstract)
{
// TODO: Should we also check symbol.GetResultantVisibility() == SymbolVisibility.Public?
var hasAnyPublicConstructors =
symbol.InstanceConstructors.Any(
(constructor) => constructor.DeclaredAccessibility == Accessibility.Public);
if (hasAnyPublicConstructors)
{
addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
}
}
}
示例12: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, INamedTypeSymbol comparableType, INamedTypeSymbol genericComparableType, Action<Diagnostic> addDiagnostic)
{
if (namedTypeSymbol.DeclaredAccessibility == Accessibility.Private || namedTypeSymbol.TypeKind == TypeKind.Interface || namedTypeSymbol.TypeKind == TypeKind.Enum)
{
return;
}
if (namedTypeSymbol.AllInterfaces.Any(t => t.Equals(comparableType) ||
(t.ConstructedFrom?.Equals(genericComparableType) ?? false)))
{
if (!(namedTypeSymbol.DoesOverrideEquals() && IsEqualityOperatorImplemented(namedTypeSymbol)))
{
addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule));
}
}
}
示例13: AnalyzeSymbol
private static void AnalyzeSymbol(INamedTypeSymbol namedTypeSymbol, INamedTypeSymbol comparableType, INamedTypeSymbol genericComparableType, Action<Diagnostic> addDiagnostic)
{
if (namedTypeSymbol.DeclaredAccessibility == Accessibility.Private || namedTypeSymbol.TypeKind == TypeKind.Interface || namedTypeSymbol.TypeKind == TypeKind.Enum)
{
return;
}
if (namedTypeSymbol.AllInterfaces.Any(t => t.Equals(comparableType) ||
(t.ConstructedFrom?.Equals(genericComparableType) ?? false)))
{
if (!(namedTypeSymbol.OverridesEquals() && namedTypeSymbol.ImplementsComparisonOperators()))
{
// CA1036: {0} should override Equals since it implements IComparable.
addDiagnostic(namedTypeSymbol.CreateDiagnostic(Rule, namedTypeSymbol.Name));
}
}
}
示例14: AnalyzeNamedTypeSymbol
private static void AnalyzeNamedTypeSymbol(INamedTypeSymbol symbol, Action<Diagnostic> addDiagnostic)
{
foreach (var parameter in symbol.TypeParameters)
{
if (!HasCorrectPrefix(parameter, 'T'))
{
addDiagnostic(parameter.CreateDiagnostic(TypeParameterRule));
}
}
if (symbol.TypeKind == TypeKind.Interface &&
symbol.IsPublic() &&
!HasCorrectPrefix(symbol, 'I'))
{
addDiagnostic(symbol.CreateDiagnostic(InterfaceRule));
}
}
示例15: AnalyzeSymbol
public override void AnalyzeSymbol(INamedTypeSymbol symbol, Compilation compilation, Action<Diagnostic> addDiagnostic, AnalyzerOptions options, CancellationToken cancellationToken)
{
var disposableType = WellKnownTypes.IDisposable(compilation);
if (disposableType != null && !symbol.AllInterfaces.Contains(disposableType))
{
var disposableFields = from member in symbol.GetMembers()
where member.Kind == SymbolKind.Field && !member.IsStatic
let field = member as IFieldSymbol
where field.Type != null && field.Type.AllInterfaces.Contains(disposableType)
select field;
if (disposableFields.Any())
{
addDiagnostic(symbol.CreateDiagnostic(Rule, symbol.Name));
}
}
}