216 votesDaniel Grunwald commented
The problem is that such complex attribute values cannot be directly represented in IL. A solution to that could be to compile such an attribute into a *method* that constructs the attribute instance as runtime. Then C# could support arbitrary expressions in attributes just by compiling them into that method.
Of course, this also requires changes to the metadata format and System.Reflection to support such method-based attributes.
189 votesDaniel Grunwald commented
I think this is a great idea; but it should allow only the following interfaces:
These three are implemented by arrays, so the compiler can just pass in a simple array at the call site. And they don't allow the method to pass any modifications back to the caller.
The current workaround is to use two overloads - one that accepts the interface type, and one that accepts arrays only so that it can use params.