52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal static class AttributeDataExtensions
|
|
{
|
|
internal static int IndexOfAttribute(this ImmutableArray<CSharpAttributeData> attributes, Symbol targetSymbol, AttributeDescription description)
|
|
{
|
|
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
|
|
for (int i = 0; i < attributes.Length; i++)
|
|
{
|
|
if (attributes[i].IsTargetAttribute(targetSymbol, description))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
internal static CSharpSyntaxNode GetAttributeArgumentSyntax(this AttributeData attribute, int parameterIndex, AttributeSyntax attributeSyntax)
|
|
{
|
|
return ((SourceAttributeData)(object)attribute).GetAttributeArgumentSyntax(parameterIndex, attributeSyntax);
|
|
}
|
|
|
|
internal static string? DecodeNotNullIfNotNullAttribute(this CSharpAttributeData attribute)
|
|
{
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
|
|
ImmutableArray<TypedConstant> commonConstructorArguments = ((AttributeData)attribute).CommonConstructorArguments;
|
|
if (commonConstructorArguments.Length == 1)
|
|
{
|
|
TypedConstant val = commonConstructorArguments[0];
|
|
string result = default(string);
|
|
if (((TypedConstant)(ref val)).TryDecodeValue<string>((SpecialType)20, ref result))
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal static Location GetAttributeArgumentSyntaxLocation(this AttributeData attribute, int parameterIndex, AttributeSyntax? attributeSyntaxOpt)
|
|
{
|
|
if (attributeSyntaxOpt == null)
|
|
{
|
|
return NoLocation.Singleton;
|
|
}
|
|
return ((SyntaxNode)((SourceAttributeData)(object)attribute).GetAttributeArgumentSyntax(parameterIndex, attributeSyntaxOpt)).Location;
|
|
}
|
|
}
|