Search code examples
.netexpression-treesoptional-arguments

Optional Arguments in an Expression Tree


I have (tried) to pass an expression of a call to a method that takes optional parameters and encountered the problem described in this Q&A. It came up in the context of a unit test.

Eric Lippert said that named argument support in expression trees is expensive. What makes this so? Have I conflated optional arguments with named?


Solution

  • Eric Lippert said that named argument support in expression trees is expensive. What makes this so?

    It's a complicated feature that needs careful design, implementation, testing and documentation, and may cause maintenance burdens in the future.

    All this work must be done by experts, all of whom are likely to be pretty busy people doing other work.

    The feature will take a great deal of time and effort, and likely require coordinating the work of multiple people; coordination also takes time and effort.

    If you have a team of people who are willing to do this work for free, please do so and submit a pull request.

    If you have a team of people who are willing to do this work, and you'll pay their salaries, again, please do so, and submit a pull request.

    If you do not, but you want other people to do this work for you, then your job is to convince those people that the best use of their time is implementing this feature for you. This is not the right forum to make that case; make the case on the github forum for Roslyn.

    Have I conflated optional arguments with named?

    It sure sounds like it. But supporting optional arguments in expression trees is also a potentially expensive feature.