是否可以在值元组中定义可选或默认属性?
例如,在下面的值元组中,这Func<Type> type = null
将是可选的:
public static void MustMatch(params
(Func<T, object> prop, Func<dynamic, dynamic> value, Func<Type> type = null)[] mappings)
是否可以在值元组中定义可选或默认属性?
例如,在下面的值元组中,这Func<Type> type = null
将是可选的:
public static void MustMatch(params
(Func<T, object> prop, Func<dynamic, dynamic> value, Func<Type> type = null)[] mappings)
不,但是您可以创建一个具有默认参数的工厂方法
public static (Func<T, object> prop, Func<dynamic, dynamic> value, Func<Type> type) Param(
Func<T, object> prop, Func<dynamic, dynamic> value, Func<Type> type = null)
{
return (prop, value, type);
}
与(同班)通话
MustMatch(
Param(t => 5, d => "hello"),
(t => 7, d => "world", () => typeof(string))
);