【发布时间】:2013-06-06 16:53:18
【问题描述】:
我有这样的方法:
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
Expression<Func<T, bool>> whereClause = null,
Expression<Func<T, object>> orderClause = null,
string selectedvalue = null) where T : class
{}
到目前为止一切顺利... 但是我需要在 Where 和 Order 子句中添加 List 选项,所以我添加了更多 3 个新方法:
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
IList<Expression<Func<T, bool>>> listWhereClause = null,
IList<Expression<Func<T, object>>> listOrderClause = null,
string selectedvalue = null) where T : class
{}
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
IList<Expression<Func<T, bool>>> listWhereClause = null,
Expression<Func<T, object>>> orderClause = null,
string selectedvalue = null) where T : class
{}
public static void Fill<T> (this DropDownList control,
Expression<Func<T, object>> value,
Expression<Func<T, bool>>> whereClause = null,
IList<Expression<Func<T, object>>> listOrderClause = null,
string selectedvalue = null) where T : class
{}
问题是现在我得到了不明确的调用错误... 解决这个问题的最佳选择是什么(不增加方法数)?
【问题讨论】:
-
您是否有理由不想让调用者自己调用
Select、Where、OrderBy等来生成查询?为什么要抓住所有这样的表达呢?看起来麻烦多于其价值,并且会大大降低过程中的可读性。 -
1.没有 C# 4.5,您可能会混淆 C# 5.0 和 .Net 4.5。 2.这不是C# 5.0特有的,可选参数是在C# 4.0中添加的。
标签: c# c#-4.0 optional-parameters