本文整理汇总了C#中ISymbol.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ISymbol.HasAttribute方法的具体用法?C# ISymbol.HasAttribute怎么用?C# ISymbol.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISymbol
的用法示例。
在下文中一共展示了ISymbol.HasAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckMember
/// <summary>
/// Checks whether the <paramref name="symbol" />'s implementing member for <paramref name="interfaceMember" /> has the
/// correct port kind.
/// </summary>
/// <param name="context">The context in which the analysis should be performed.</param>
/// <param name="symbol">The symbol that should be analyzed.</param>
/// <param name="compilation">The compilation the symbol is declared in.</param>
/// <param name="interfaceMember">The interface member that should be checked.</param>
private static void CheckMember(SymbolAnalysisContext context, ITypeSymbol symbol, Compilation compilation, ISymbol interfaceMember)
{
var implementingMember = symbol.FindImplementationForInterfaceMember(interfaceMember);
var interfaceIsRequired = interfaceMember.HasAttribute<RequiredAttribute>(compilation);
var interfaceIsProvided = interfaceMember.HasAttribute<ProvidedAttribute>(compilation);
var implementationIsRequired = implementingMember.HasAttribute<RequiredAttribute>(compilation) || implementingMember.IsExtern;
var implementationIsProvided = implementingMember.HasAttribute<ProvidedAttribute>(compilation) || !implementingMember.IsExtern;
// If we can't uniquely classify the port kind of either the interface member or the implementation,
// there is another problem that another analyzer deals with. So let's just ignore it here.
if ((interfaceIsRequired && interfaceIsProvided) || (implementationIsProvided && implementationIsRequired))
return;
var location = implementingMember.ContainingType.Equals(symbol) ? implementingMember : symbol;
if (interfaceIsRequired && !implementationIsRequired)
{
_requiredPortImplementedAsProvidedPort.Emit(context, location,
implementingMember.ToDisplayString(), interfaceMember.ToDisplayString());
}
if (interfaceIsProvided && !implementationIsProvided)
{
_providedPortImplementedAsRequiredPort.Emit(context, location,
implementingMember.ToDisplayString(), interfaceMember.ToDisplayString());
}
}
示例2: HasNotNullAttribute
private static bool HasNotNullAttribute(ISymbol symbol)
{
return symbol.HasAttribute("NotNullAttribute");
}