开发者

How do I extend the Func delegate to contain more than the maximum four parameters?

开发者 https://www.devze.com 2022-12-11 09:19 出处:网络
I have b开发者_运维技巧een using LINQ with compiled queries, basically passing into the compiled query using Func but the problem is that it has a maximum of four parameters.

I have b开发者_运维技巧een using LINQ with compiled queries, basically passing into the compiled query using Func but the problem is that it has a maximum of four parameters.

Is it good practice to extend this?

Is there any way to extend this or should I create my own delegate?

Sometimes I need to pass six params and others five and others four or less... so with four or less I could continue using the Func delegate.

Currently passing in data context and a mix of the params I need are dependent on each individual compiled query.


Just declare your own delegates - it's only a single line of code to do so. See my examples for declaring the .NET 3.5 delegates in .NET 2.0 for a sort of template, if you need it.

I don't know how well this will work with LINQ compiled queries - hopefully it won't be a problem, but your use case isn't quite clear enough to me to say for sure.

Note that in .NET 4.0 there's support for Func/Action with up to 8 parameters.


What Jon said plus...

As you've suggested, generally you shouldnt end up with too many params - generally you should find some uniting concept jumping out telling you to Introduce Parameter Object. Having said that, 4 wouldnt be the place where I'd place a 'that's just crazy' line.

0

精彩评论

暂无评论...
验证码 换一张
取 消