Hi I’m trying to use this overload …
public ApiAllowableValuesAttribute(string name, Func<string[]> listAction)
but it seems is not a valid signature for an attribute
How can I use it ?
thank you
Enrico
There’s an example for using it to annotate enums in the SwaggerTestService:
public enum MyColor
{
Red,
Green,
Blue
}
public class SwaggerTest
{
[ApiMember]
[ApiAllowableValues("Color", typeof(MyColor))] //Enum
public MyColor Color { get; set; }
}
Note metadata attributes is a compile time constants so you can only specify built-in constant data types, not delegates. So constructors with delegates can only be called in code.
I know
ApiAllowableValuesAttribute(string name, Func listAction)
can only be called in code, I wanted to know how .
I managed to do it this way using AddAttributes … and it works
typeof (GetCountriesProjection).GetProperty(“RequestedFields”)
.AddAttributes(new ServiceStack.ApiAllowableValuesAttribute(“RequestedFields”, () => typeof(CountryProjection1).GetProperties().Select(p => p.Name).ToArray()));
ok yeah that’s how you would add the attribute at runtime.
Yes, I guess it’s the only way you can go to use that constructor overload .