Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of attributes have any guarantees?

If multiple attributes are applied to a member, e.g.

[Foo]
[Bar]
void Baz() { ... }

Then are any guarantees made by the CLR/.NET specifications as to what order they will be retrieved in when retrieved by reflection (e.g. Attribute.GetCustomAttributes)? The documentation for these methods does not make it explicit, and while it does seem to be the case that they are returned in the order they are applied, I don't want to rely on undocumented behaviour as that's just asking for trouble.

As for why this might be important, imagine the attributes are used to indicate that the method should have a series of interceptors, which should run in a specific order.

like image 991
Greg Beech Avatar asked Feb 11 '10 11:02

Greg Beech


People also ask

Does attribute order matter?

The order of attributes in HTML elements doesn't matter at all.

Does order of attributes matter C#?

No, the order of attributes does not matter.

Can attributes be specified in any order?

No, attribute order is irrelevant. Show activity on this post. Any order is valid HTML but just out of curiosity I wondered whether the external file would get downloaded sooner if the href attribute was first.


1 Answers

No from 17.2 Attribute specification it does not seems so.

The order in which attributes are specified in such a list, and the order in which sections attached to the same program entity are arranged, is not significant. For instance, the attribute specifications [A][B], [B][A], [A, B], and [B, A] are equivalent.

like image 187
Adriaan Stander Avatar answered Sep 20 '22 19:09

Adriaan Stander