How can I easily create a Func<T> from a method name?

59 views Asked by At

Trying to reduce code duplication in a project which wraps a modern Wcf interface around an old Dll which used to power an Asmx web service.

I'm trying to write a generic helper method which takes 4 types (Old and New versions of the Input and Output types), the input document and a Func pointing at the method in the old dll.

private static WcfOutType WrapCallAroundOldBl<WcfOutType, WcfInType, LinqOutType, LinqInType>(WcfInType input, Func<LinqInType, LinqOutType> method)

Thought I could do something like this:

        var output = WrapCallAroundOldBl<
            WcfOutputTypeName, 
            WcfINputTypeName, 
            LinqToXsdOutputTypeName,
            LinqToXsdInputTypeName>(input, Our.Old.Dll.Methods.MethodName);
        return output;

But I get:

cannot convert from 'method group' to 'System.Func<OutputTypeName, InputTypeName>'

This works:

        var output = WrapCallAroundOldBl<
            WcfOutputTypeName, 
            WcfINputTypeName, 
            LinqToXsdOutputTypeName,
            LinqToXsdInputTypeName>(input, i => Our.Old.Dll.Methods.MethodName(i));
        return output;

But I was wondering is there is anyway to turn these "method groups" directly into the Func. Just extract the delegate somehow.

0

There are 0 answers