params modifier applied to Generic Type arguments #9439
-
SDKs often have dozens of overloads like this one from SqlLite: public virtual void CreateFunction<TState, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>(string name, TState state, Func<TState, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>? function, bool isDeterministic = false)
=> CreateFunctionCore(name, 15, state, IfNotNull<TState, TResult>(function, (s, r) => function!(s, r.GetFieldValue<T1>(0)!, r.GetFieldValue<T2>(1)!, r.GetFieldValue<T3>(2)!, r.GetFieldValue<T4>(3)!, r.GetFieldValue<T5>(4)!, r.GetFieldValue<T6>(5)!, r.GetFieldValue<T7>(6)!, r.GetFieldValue<T8>(7)!, r.GetFieldValue<T9>(8)!, r.GetFieldValue<T10>(9)!, r.GetFieldValue<T11>(10)!, r.GetFieldValue<T12>(11)!, r.GetFieldValue<T13>(12)!, r.GetFieldValue<T14>(13)!, r.GetFieldValue<T15>(14)!)), isDeterministic); This is boring boilerplate code. It distracts the code author and the code reader. It's currently a necessary evil. This is because the What if it could though? What if all of the overloads for CreateFunction<TState, TResult, params T[]> All of the elements There's more complexity there to be worked out, like the syntax for specifying generic type constraints on generic params... but I figured I'd check whether this request has been made before and if there are already other extensive discussions on the topic before getting too enthusiastic. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
See: #2330 |
Beta Was this translation helpful? Give feedback.
See: #2330