I have an attribute CustomAuthorizethat checks if a user has access to functions (a user or a role can be associated with elements from a hierarchical set of functions).
For this action method ...
[CustomAuthorize("Security.Admin.ManageWidgets.Update")]
This works, but I am concerned that changes to the Security object may cause problems that will not be detected before execution. I understand that I can write unit tests to mitigate this risk, but I would like to know if the attribute parameter can be checked at compile time. I also like when Intellisense helps me type this expression.
Ideally, I could pass in a lambda expression.
[CustomAuthorize(i => i.Admin.ManageWidgets.Update)]
Unfortunately, this one is currently not possible ( additional information from Microsoft ).
I also tried to encapsulate the expression, hoping that it would be evaluated and then passed to the attribute as a string, but it also could not be compiled with the same error (the expression cannot contain anonymous methods or lambda expressions).
[CustomAuthorize(LambdaToString(i => i.Admin.ManageWidgets.Update))]
How to add some development time / runtime support for custom attribute parameters?
source
share