lundi 9 mars 2020

Factory of Func Delegate

I am trying to figure out a way using which I could get a business function as a Func delegate. I am trying to write business logic as a pure function so that based on the requirement my provider or factory could return me just that piece of business logic rather than the entire object which has methods that I don't need for certain code logic flow.

public static Func<IArgs, IOut> GetFunc()
{
    return new Func<IArgs, IOut>((DataParams p) => new OutObject());
}

The issue is that even though DataParams and OutObject are implementing IArgs and IOut, the compiler warns me of an implicit casting error. Making the interfaces covariant with T makes it hard for me to figure out how should I implement this.

Primary Objective - I want to write a factory that throws out functions that take objects holding a different set of prameters to be passed as Get-Set properties. This function would return me an object after it processes the data based on the parameter passed.

Aucun commentaire:

Enregistrer un commentaire