10 ms·
Lamba/Func/Expressions are doing exactly this in C#, there is no instantiation required. Creating a unusable Ref object is jumping through hoops. You can parse
by 0xcoffee 3y ago
Lamba/Func/Expressions are doing exactly this in C#, there is no instantiation required. Creating a unusable Ref object is jumping through hoops.
You can parse an expression to serialize it and run it on a different server etc
See e.g. https://github.com/6bee/Remote.Linq https://github.com/6bee/Remote.Linq
- kodablah 3y agoHrmm, I will investigate using an expression tree for this (now's the time while it is alpha). I was hoping to avoid people having to create lambdas. I hope I don't run into overload ambiguity with the existing `ExecuteActivity` calls where you can just pass an existing method as Func<T, TResult> param. I will investigate this approach, thanks! Of course the "Ref" pattern is user-choice/suggested-pattern, it's not a requirement in any of our calls that just take simple delegates however you can create those delegates. So I may be able to work it in there.
- progmetaldev 3y agoIf it's possible to use both approaches without cluttering your API, that may be the best solution. I know a lot of more junior devs that have a difficult time wrapping their head around expressions in C#. Excellent library!
- kodablah 3y agoAfter looking at it, I am concerned it is not possible for a clean experience. We have to give guidance and samples and we have to choose a way of referencing methods in those. Having ambiguous approaches is a bit rough. We may have to just move to expressions.
- progmetaldev 3y agoI completely understand. Either way, I still think the library is great and appreciate the work done to create it.
- jcparkyn 3y agoAs another point of reference, Hangfire also uses expressions for a similar use-case and it seems to work quite well. E.g. https://docs.hangfire.io/en/latest/background-methods/passing-dependencies.html https://docs.hangfire.io/en/latest/background-methods/passin... BackgroundJob.Enqueue<EmailSender>(x => x.Send(13, "Hello!"));
- evntdrvn 3y agoYup!!!