As is well known, in C# one can specify the target of a custom attribute specification, as in the example
[method: SomeDecoration]
[return: SomeOtherMark]
int MyMethod();
where the "targets" method: and return: help specify what element in the code the attribute belongs to.
According to the C# Language Specification, the following attribute targets exist:
assemblymodulefieldeventmethodparampropertyreturntypeSome of them, like field, are always redundant, since it is always clear what the attribute "sits" on without specifying them.
However there does exist (at least in the implementation and version of Visual C# I have here) an additional attribute target, namely:
typevarwhich is allowed for example in the code
class MyGenericCollection<[typevar: HereYouSee] TItem> // legal
{
}
The attribute target typevar, just like field and others, is never required.
My question: Does anyone know the historic reason why typevar: is not mentioned in the specification or documentation? Was this simply forgotten when the 2.0 version of the C# Language Specification was written? Or if it was not an oversight, why is it implemented at all?
Actually, typevar attribute target is documented, but it seems that only in the standardized C# 2.0 Language Specification:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf#page=399
Neither C# 3.0, nor 5.0 Language Specification mentions typevar. (I didn't find C# 4.0 spec.)
So answering your second question, no, it wasn't forgotten in C# 2.0, but it is forgotten since then :) I think this must be an oversight, since the typevar attribute target is still (C# 5.0) valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With