Passing delegates to Attributes #7727
Unanswered
Kralizek
asked this question in
Language Ideas
Replies: 1 comment
-
See: #343
Attributes are more restrictive than that. They only support a subset of known types, as the runtime needs to be able to reconstitute them from the metadata blob at runtime. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Attributes can only accept constant values. In a way, delegates are constant.
How difficult would it be to allow passing delegates to attributes?
My concrete use case is the following:
When using AutoFixture glue library with NUnit, I can use an attribute inheriting from AutoDataAttribute to customize how values are created before being passed to the actual test.
Unfortunately, different tests might want the same type being setup differently.
Today, the only option is to create multiple copies of the same attribute, one for each use case.
By accepting a delegate, both inlined or just by reference, I could simply use the delegate to specify the custom setup per test without the need of creating multiple copies of the same attribute.
I understand that the inlined syntax might be horrible, but it would help a lot.
Beta Was this translation helpful? Give feedback.
All reactions