Introduce globals for some general lambda functions/actions #97026
Unanswered
Timo-Weike
asked this question in
Ideas
Replies: 1 comment
-
If that's an issue (one cached object per call site), I'd prefer to see that addressed at the C# compiler level (one cached object per assembly) rather than creating a second way to express an empty lambda. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
If an API wants to consume some form of
Action
orFunc
to convert something or create a side effect, but the user does not want anything to happen and the API checks fornull
values. Then the way most people go is to write something likeDoStuff(_ => {})
. However this has the potential to create an unnecessary amount ofAction
orFunc
objects.A similar problem existed for empty strings, arrays and
IEnumerable
, there the runtime got the staticEmpty
methods to return a single empty array for each type.This pattern would also benefit the
Action
andFunc
types.My idea is to add (maybe more) an
Empty
property forAction
typesand
Identity
forFunc<T, T>
.Something like
Beta Was this translation helpful? Give feedback.
All reactions