本文整理汇总了C#中Symbol.GetAttributeTarget方法的典型用法代码示例。如果您正苦于以下问题:C# Symbol.GetAttributeTarget方法的具体用法?C# Symbol.GetAttributeTarget怎么用?C# Symbol.GetAttributeTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol
的用法示例。
在下文中一共展示了Symbol.GetAttributeTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyAttributeUsageTarget
/// <summary>
/// Verify if the attribute type can be applied to given owner symbol.
/// Generate a diagnostic if it cannot be applied
/// </summary>
/// <param name="ownerSymbol">Symbol on which the attribute is applied</param>
/// <param name="attributeType">Attribute class for the attribute</param>
/// <param name="node">Syntax node for attribute specification</param>
/// <param name="attributeLocation">Attribute target specifier location</param>
/// <param name="diagnostics">Diagnostics</param>
/// <returns>Whether attribute specification is allowed for the given symbol</returns>
internal bool VerifyAttributeUsageTarget(Symbol ownerSymbol, NamedTypeSymbol attributeType, AttributeSyntax node, AttributeLocation attributeLocation, DiagnosticBag diagnostics)
{
var attributeUsageInfo = attributeType.AttributeUsageInfo(Compilation);
if (attributeUsageInfo != null)
{
AttributeTargets attributeTarget;
if (attributeLocation == AttributeLocation.Return)
{
// attribute on return type
attributeTarget = AttributeTargets.ReturnValue;
}
else
{
attributeTarget = ownerSymbol.GetAttributeTarget();
}
if ((attributeTarget & attributeUsageInfo.ValidTargets) != 0)
{
return true;
}
// generate error
Error(diagnostics, ErrorCode.ERR_AttributeOnBadSymbolType, node, GetAttributeNameFromSyntax(node), attributeUsageInfo.GetValidTargetsString());
}
return false;
}