generics - Any way to have some type parameters inferred from other type parameters' constraints in C#? -


suppose have following code:

interface iwidget { }  interface iwidgetfactory<twidget>     twidget : iwidget { }  twidgetfactory createfactory<twidgetfactory, twidget>()     twidgetfactory : iwidgetfactory<twidget>     twidget : iwidget {     return ... } 

whenever call createfactory() must pass in both twidgetfactory , twidget type parameters. seems unnecessary, because twidgetfactory has constraint such specialisation of must specify twidget. there way can have twidget inferred automatically when calling createfactory(), if must add kind of helper methods it?

(the above simple example, can more complicated in practice, save lot of complexity.)

without seeing body of createfactory, difficult tell you're doing. based on return type, suspect createfactory doesn't use twidget type parameter interface. in case, relax generic constraints bit?

interface iwidget { }  interface iwidgetfactory {} // new non-generic base interface  interface iwidgetfactory<twidget> : iwidgetfactory     twidget : iwidget { }  // generic constraints wind not specific,  // still provide level of restriction // twidget can no longer used within method. twidgetfactory createfactory<twidgetfactory>()     twidgetfactory : iwidgetfactory {     return ... } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -