gleb.kudr
gleb.kudr

Reputation: 1508

Anonymous type function declaration

Let's have a function:

Func<argsFoo, resultFoo> foo= x=>new resultFoo(x);
Func<argsBar, resultBar> bar= x=>new resultBar(x);
Func<argsBaz, resultBaz> baz= x=>new resultBaz(x);

I want to create a complex function which uses all this functions declared above.

Like this:

Func
<
    Func<argsFoo, resultFoo>,
    Func<argsBar, resultBar>,
    Func<argsBaz,resultBaz>,
    fooBarBazResult
> fooBarBaz=...

The point is such declaration is killing the readability of the programm. Type inference is not working in this case.

Question: can I use something like this?

FooBarBaz<typeof(foo),typeof(bar)>,typeof(baz)>>

I have tried and answer is no. May be anyone has another solution to make shorter the composed function declarations?

Upvotes: 0

Views: 157

Answers (2)

Rafal
Rafal

Reputation: 12619

You can always declare your own delegate that will be describing your methods:

public delegate resultMy MyDelegate(argsMy arg)

and use the shorter name MyDelegate

Func<FooDelagate, BatDelegate, BazDelegate>

and even that delegate you can name to simplify you code.

Upvotes: 1

It&#39;sNotALie.
It&#39;sNotALie.

Reputation: 22794

Well, you could add a using statement at the top of your file that simplifies that:

using SomeName = Func<Func<ArgsFoo, ResultFoo>, Func<ArgsBar, ResultBar>, Func<ArgsBaz, ResultBaz>>;

And then you couls just use it as this:

SomeName myFunc = //the func

Upvotes: 0

Related Questions