Proposal: Syntactic Sugar in C# for Forwarding Parameters #9693
Unanswered
Leucist
asked this question in
Language Ideas
Replies: 1 comment 4 replies
-
The scenarios 1 and 2 can be accomplished today with a source generator - just decorate |
Beta Was this translation helpful? Give feedback.
4 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.
-
Idea Overview
The idea is to introduce a new syntax in C# that allows developers to create wrapper methods without having to explicitly declare the parameters again. This would enhance code readability and reduce redundancy, especially when dealing with methods that simply forward calls to other methods.
Proposed Syntax
The proposed syntax could look something like this:
In this case, the ... would automatically infer the parameters from the method being wrapped, allowing for a cleaner and more concise method definition.
Consideration of Options
I have considered three potential example scenarios for how this could work with lambda operators or plain methods:
A(...) => _service.B(...);
This option may not be applicable for methods that have overloads. For those, we could use the second option:
A(...) => _service.B( /*specific params*/ );
This ensures the correct method will be called.
WrapA(...) {}
In this case, the method body must contain a pairing "..." in some method call.
Could look something like this:
Benefits
Personal Experience and Invitation for Discussion
While implementing a caching system for mathematical operations in my project, I initially used a simple wrapper for a method and thought that adding such syntactic sugar could be quite convenient. This is a small detail that may not significantly change the usual development process, but it could simplify certain routine tasks.
I want to propose this idea as a concept for potential syntactic sugar, but not to push it rigidly. Instead, I encourage the community to engage in open discussion. I would be glad to hear both suggestions as well as concerns – if anyone notices a significant oversight regarding this novelty.
Beta Was this translation helpful? Give feedback.
All reactions