Attribute properties
Closed this issue · 3 comments
bugproof commented
Is it possible to generate something like:
MyAttribute("somevalue", MyProperty = "something")
bugproof commented
I solved it creating my own argument and using Roslyn explicitly.
class PropertyInitializationArgument : Argument
{
public string PropertyName { get; set; }
public object Value { get; set; }
public PropertyInitializationArgument(string propertyName, object value) : base(null)
{
PropertyName = propertyName;
Value = value;
}
protected override ArgumentSyntax CreateArgumentSyntax()
{
var value = Value.ToString();
if (Value is bool)
{
value = value.ToLower();
}
return SyntaxFactory.Argument(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(PropertyName), SyntaxFactory.IdentifierName(value)));
}
}
MilleBo commented
That's actually really nice to have. Could you maybe create a new PR with that class and a small unit test? Or is it okay if I add it myself?
bugproof commented
Feel free to add it yourself. I just needed something quick and it works for me.