本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData.IsSecurityAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpAttributeData.IsSecurityAttribute方法的具体用法?C# CSharpAttributeData.IsSecurityAttribute怎么用?C# CSharpAttributeData.IsSecurityAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.CSharpAttributeData
的用法示例。
在下文中一共展示了CSharpAttributeData.IsSecurityAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateAttributeUsage
/// <summary>
/// Validate attribute usage target and duplicate attributes.
/// </summary>
/// <param name="attribute">Bound attribute</param>
/// <param name="node">Syntax node for attribute specification</param>
/// <param name="compilation">Compilation</param>
/// <param name="symbolPart">Symbol part to which the attribute has been applied.</param>
/// <param name="diagnostics">Diagnostics</param>
/// <param name="uniqueAttributeTypes">Set of unique attribute types applied to the symbol</param>
private bool ValidateAttributeUsage(
CSharpAttributeData attribute,
AttributeSyntax node,
CSharpCompilation compilation,
AttributeLocation symbolPart,
DiagnosticBag diagnostics,
HashSet<NamedTypeSymbol> uniqueAttributeTypes)
{
Debug.Assert(!attribute.HasErrors);
NamedTypeSymbol attributeType = attribute.AttributeClass;
AttributeUsageInfo attributeUsageInfo = attributeType.GetAttributeUsageInfo();
// Given attribute can't be specified more than once if AllowMultiple is false.
if (!uniqueAttributeTypes.Add(attributeType) && !attributeUsageInfo.AllowMultiple)
{
diagnostics.Add(ErrorCode.ERR_DuplicateAttribute, node.Name.Location, node.Name);
return false;
}
// Verify if the attribute type can be applied to given owner symbol.
AttributeTargets attributeTarget;
if (symbolPart == AttributeLocation.Return)
{
// attribute on return type
Debug.Assert(this.Kind == SymbolKind.Method);
attributeTarget = AttributeTargets.ReturnValue;
}
else
{
attributeTarget = this.GetAttributeTarget();
}
if ((attributeTarget & attributeUsageInfo.ValidTargets) == 0)
{
// generate error
diagnostics.Add(ErrorCode.ERR_AttributeOnBadSymbolType, node.Name.Location, node.Name, attributeUsageInfo.GetValidTargetsErrorArgument());
return false;
}
if (attribute.IsSecurityAttribute(compilation))
{
switch (this.Kind)
{
case SymbolKind.Assembly:
case SymbolKind.NamedType:
case SymbolKind.Method:
break;
default:
// CS7070: Security attribute '{0}' is not valid on this declaration type. Security attributes are only valid on assembly, type and method declarations.
diagnostics.Add(ErrorCode.ERR_SecurityAttributeInvalidTarget, node.Name.Location, node.GetErrorDisplayName());
return false;
}
}
return true;
}