FUNC键5个参数 [英] Func for 5 arguments

查看:153
本文介绍了FUNC键5个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正与System.Func,但已经达到了一个绊脚石吧。

I am working with System.Func but have reached a stumbling block with it.

System.Func<TReturn> // (no arg, with return value)
System.Func<T, TReturn> // (1 arg, with return value)
System.Func<T1, T2, TReturn> // (2 arg, with return value)
System.Func<T1, T2, T3, TReturn> // (3 arg, with return value)
System.Func<T1, T2, T3, T4, TReturn> // (4 arg, with return value)

它接受最多为4个参数。

The max it accepts is 4 arguments.

有什么办法这个延伸到5个参数的?

Is there any way of extending this to 5 arguments?

推荐答案

您有几个选项之一是定义委托你的自我这将是这样的:

You have a few options one is to define the delegate your self which would look like:

public delegate TResult Func<T1,T2,...,TN,TResult>(T1 arg1, T2 arg2,...,TN argN); 

你基本上可以将其定义为任何数量的参数(高于4,因为你可能会得到一个名称冲突,否则)

you can basically define it for any number of arguments (higher than 4 since you might get a name clash otherwise)

或者你可以用你的论点成为某种形式的结构,使您可以使用已定义为您的Func键代表之一。

or you can wrap your arguments into a structure of some sort so that you can use one of the Func delegates already defined for you.

在任何情况下,你应该担心的方法签名,如果你不能使用predefined Func键代表之一。很多时候的参数一长串的气味,往往导致你实现,该方法是做给多少(无关)的工作。

In any case you should worry about the method signature if you cannot use one of the predefined Func delegates. Quite often long lists of parameters are a smell that often leads you to realize that the method is doing to much (unrelated) work.

我个人的做法是找出其中的设计失败和纠正,而不是正确的哪些是最常见的症状(在这种情况下,定义一个函数功能有足够agruments的可以的是固定的症状并不是说这是因为我不知道你的code)

My personal approach would thus be to figure out where the design failed and correct that rather than correct what is most often the symptom (in this case defining a Func with sufficient agruments could be fixing the symptom not saying that it is since I don't know your code)

这篇关于FUNC键5个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆