Replies: 15 comments 2 replies
-
This will require some minor changes to the C# spec as currently it doesn't seem that the compiler can handle I'm also going to assume that this does not include attempting to also apply attributes on the parameters generated to support enclosing the local scope? Any concerns regarding whether the compiler generates a static method with |
Beta Was this translation helpful? Give feedback.
-
The main work to be done here is validating that the proposed syntax is unambiguous. Otherwise, it should be pretty straightforward to thread this through the compiler. |
Beta Was this translation helpful? Give feedback.
-
I've also had a need for the opposite, to prevent a function from being inlined in order to help a caller of it get inlined (and with minimal assembly), e.g. Data Get()
{
return _data ?? Initialize();
[MethodImpl(MethodImplOptions.NoInlining)]
Data Initialize()
{
... // expensive code to initialize _data;
return _data;
}
} |
Beta Was this translation helpful? Give feedback.
-
... Just a "bump" as @stephentoub commented: I would also like to apply `MethodImpl' to local functions. It might be nifty if it was also possible with lambdas ... ( |
Beta Was this translation helpful? Give feedback.
-
Any updates here? I am interested in the performance benefits of |
Beta Was this translation helpful? Give feedback.
-
I find it funny that you want |
Beta Was this translation helpful? Give feedback.
-
I wanted NoInlining recently too :D |
Beta Was this translation helpful? Give feedback.
-
Just hit this one today. I wanted to use |
Beta Was this translation helpful? Give feedback.
-
Another case is for public static IAsyncEnumerable<T> Where<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));
return Core();
async IAsyncEnumerable<T> Core([EnumeratorCancellation] CancellationToken token = default)
{
await foreach (var item in source.WithCancellation(token))
{
if (predicate(item))
{
yield return item;
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
This has been implemented. I am currently using dotnet SDK 3.1.301 and I can put the |
Beta Was this translation helpful? Give feedback.
-
@Happypig375 yes, it has been implemented. We keep the issue open until we have a spec for the feature, however. |
Beta Was this translation helpful? Give feedback.
-
The design is that attributes are only allowed on local functions if they're static? |
Beta Was this translation helpful? Give feedback.
-
Nevermind, I just tried it and it doesn't appear that static is required. Phew :) |
Beta Was this translation helpful? Give feedback.
-
It is only limited to |
Beta Was this translation helpful? Give feedback.
-
I have a separate use case for adding attributes to the local function itself for use inside test methods... wanted to try something like using one local function to provide data to another local function, kinda like a "local" datasource. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Some use-cases:
Note: this needs to be tested with nullability attributes.
Relates to dotnet/roslyn#19372
Beta Was this translation helpful? Give feedback.
All reactions