带方法重载的可选参数
本文关键字:参数 方法 重载 | 更新日期: 2023-09-27 18:17:27
我有这样一个方法:
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
{}
问题是现在我得到了歧义调用错误…解决这个问题的最佳选择是什么(不增加方法计数)?
删除重载的默认值(null
)。因为你已经在默认的null
值中添加了重载,编译器根本不知道该使用哪个。