Attribute Style Preference
Not sure if #help is the right place for this but I was hoping for some thoughts on attribute style.
It goes without saying that functionally, the two styles make absolutely no difference. They are handled identically by the compiler.
I have noticed however that decompiled C#, such as when looking at lowered code in SharpLab, tends to prefer style 1. I think that's mostly because it's easier to render it as C# that way, not because of any functional reason.
Which style do you guys prefer, and what is your reasoning? Does it depend, e.g. based on the length of the attribute name or the number of attributes? Do you mix and match styles?
3 Replies
1
Different things are different things
Same reason I do
and not
I personally use style 1 as well
But yeah, your reasoning is sound. That was pretty much my thought for keeping them separate
I could see it in some cases like
[DisplayName("foo"), Alias("bar")]
since they're dealing with similar topics, but I would personally prefer the library change to allow something like [DisplayName(name: "foo", alias: "bar")]
Style 1. With no exceptions, regardless of the length. This is so that I can easily tell how many attributes I've used.
Some of my unit tests contain over 20 attributes, and if I am to do it in Style 2, it will be difficult to re-read them later.