Allow application of Attributes with "Method" AttributeUsage to expression-bodied properties #887
Replies: 7 comments
-
I think that I'd rather support that via an explicit attribute target in order to avoid ambiguity, perhaps either using System;
using System.Runtime.CompilerServices;
public class Program {
[method: MethodImpl(MethodImplOptions.AggressiveInlining)]
public string X => "X";
} |
Beta Was this translation helpful? Give feedback.
-
@HaloFour Yes, support for the
|
Beta Was this translation helpful? Give feedback.
-
Though at that point why not just write the |
Beta Was this translation helpful? Give feedback.
-
@jnm2 To be fair, this entire request is just to avoid adding the extra It does have an effect in codebases where property |
Beta Was this translation helpful? Give feedback.
-
Not entirely; when there's no
versus
...is a pretty worthwhile savings. Even if you can abide the following, there's no doubt it's clunkier than the proposed top example:
|
Beta Was this translation helpful? Give feedback.
-
Bump. If there are backwards-compatibility complications for the language or other syntactic problems with augmenting the behavior of the
|
Beta Was this translation helpful? Give feedback.
-
Would love to see some action on this. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Initially raised here.
Consider the following code:
The first attribute (on property
X
) fails to compile as it is being applied to a property, rather than a method. However, usage of the alternative syntax[method: MethodImpl(MethodImplOptions.AggressiveInlining)]
is not supported by the compiler either, and simply results in the attribute being ignored.It would be nice to be able to apply Method-level attributes to the newer expression-bodied syntax for properties without having to fall back to the slightly-less-terse version with explicit getters.
Beta Was this translation helpful? Give feedback.
All reactions