I know this surfaced many times, like in this or this question, and it is clearly written on MSDN, but if I cannot pass a function anyhow as a parameter to an attribute, how can System.ComponentModel.DataAnnotations.ValidationAttribute do it?
What am I missing here? Is it only possible for this built in attribute to have a Func< TResult > as a parameter? If it is after all possible, can it be a Func with input parameter(s) as well?
My final goal is to be able to define the function to use to serialize a property. The whole thing is runtime code-generation magic, so I don’t really need trivial alternatives to do this. I do have a workaround, but using a Func would be so much easier.
You can use a delegate as an argument to an attribute constructor – you just can’t do so declaratively.
Now in this case, it’s only a protected constructor anyway – so it’s intended to be called from the derived classes such as
RangeAttribute, which will presumably supply an appropriate delegate to the base constructor.