Replace C# Lambda Operator
I need to convert .Net 4.0 Api to .Net 2.0 Api.
Can i replace this:
public ClrBinder(IEnumerable<MethodBase> targetMethods)
: this(targetMethods.Select(method => new BinderMethod(method)))
{
}
with this:
public ClrBinder(IEnumerable<MethodBase> targetMethods)
: this(targetMethods.Select(new BinderMethod(new MethodBase())))
{
}
without changing the logic?
thank you very much!
Comment
Best Answer
Answer by Statement · Oct 25, 2015 at 04:52 PM
Provide a non-anonymous delegate.
public ClrBinder(IEnumerable<MethodBase> targetMethods)
: this(targetMethods.Select<BinderMethod>(ToBinderMethod))
{
}
private static BinderMethod ToBinderMethod(MethodBase methodBase)
{
return new BinderMethod(methodBase);
}
Super, thank you very much for the help! It seems that it is different, beause you care of passing the parameter methodBase.
It's a non-lambda, non-anonymous version of:
method => new Binder$$anonymous$$ethod(method))
Which also passes the parameter (here called "method").
$$anonymous$$y answer behaves identical with the first code snippet you provided. The second code snippet doesn't behave like the first, and looks wrong to me. You're throwing away information.