本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbol.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Symbol.GetAttributes方法的具体用法?C# Symbol.GetAttributes怎么用?C# Symbol.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbol
的用法示例。
在下文中一共展示了Symbol.GetAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckForAttributeWithArrayArgument
private void CheckForAttributeWithArrayArgument(Symbol symbol)
{
System.Diagnostics.Debug.Assert(IsTrue(GetDeclaredOrInheritedCompliance(symbol)), "Only call on compliant symbols");
CheckForAttributeWithArrayArgumentInternal(symbol.GetAttributes());
if (symbol.Kind == SymbolKind.Method)
{
CheckForAttributeWithArrayArgumentInternal(((MethodSymbol)symbol).GetReturnTypeAttributes());
}
}
示例2: GetDeclaredCompliance
/// <remarks>
/// As in dev11, we ignore the fact that CLSCompliantAttribute is inherited (i.e. from the base type)
/// (see CSemanticChecker::CheckSymForCLS). This should only affect types where the syntactic parent
/// and the inheritance parent disagree.
/// </remarks>
private bool? GetDeclaredCompliance(Symbol symbol, out Location attributeLocation)
{
attributeLocation = null;
foreach (CSharpAttributeData data in symbol.GetAttributes())
{
// Check signature before HasErrors to avoid realizing symbols for other attributes.
if (data.IsTargetAttribute(symbol, AttributeDescription.CLSCompliantAttribute))
{
NamedTypeSymbol attributeClass = data.AttributeClass;
if ((object)attributeClass != null)
{
DiagnosticInfo info = attributeClass.GetUseSiteDiagnostic();
if (info != null)
{
Location location = symbol.Locations.IsEmpty ? NoLocation.Singleton : symbol.Locations[0];
_diagnostics.Enqueue(new CSDiagnostic(info, location));
if (info.Severity >= DiagnosticSeverity.Error)
{
continue;
}
}
}
if (!data.HasErrors)
{
if (!TryGetAttributeWarningLocation(data, out attributeLocation))
{
attributeLocation = null;
}
ImmutableArray<TypedConstant> args = data.CommonConstructorArguments;
System.Diagnostics.Debug.Assert(args.Length == 1, "We already checked the signature and HasErrors.");
// Duplicates are reported elsewhere - we only care about the first (error-free) occurrence.
return (bool)args[0].Value;
}
}
}
return null;
}