Код: Выделить всё
private static bool HasAttribute(SyntaxNodeAnalysisContext context, string attributeName, out PropertyAttributeData data)
{
var propertyDeclarationSyntax = (PropertyDeclarationSyntax)context.Node;
data = new PropertyAttributeData
{
Type = propertyDeclarationSyntax.Type
};
var propertyAttribute = propertyDeclarationSyntax.AttributeLists.FirstOrDefault()
?.GetAttributes(context.Compilation)
?.FirstOrDefault(attr => attr.AttributeClass?.Name == attributeName);
if (propertyAttribute == null)
{
return false;
}
data.AttributeData = propertyAttribute;
data.ConstructorArg1 = propertyAttribute.ConstructorArguments.FirstOrDefault();
if (propertyAttribute.ConstructorArguments.Length > 1)
{
data.ConstructorArg2 = propertyAttribute.ConstructorArguments.Skip(1).FirstOrDefault();
}
return true;
}
< /code>
Тем не менее, это то, где я как бы застрял. Я использовал context.node.getLocation
Как я бы получил местоположение rast атрибут или первый/второй аргумент IT? Любое руководство будет оценено. Tia.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -parameter