0

Is it possible to define an optional or default attribute within a value tuple?

for example in the below value tuple the Func<Type> type = null will be optional:

public static void MustMatch(params
    (Func<T, object> prop, Func<dynamic, dynamic> value, Func<Type> type = null)[] mappings)
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
Farhad-Taran
  • 6,282
  • 15
  • 67
  • 121

1 Answers1

0

No. But you can create a factory method having a default parameter

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);
}

Call with (within same class)

MustMatch(
    Param(t => 5, d => "hello"),
    (t => 7, d => "world", () => typeof(string))
);
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188