包裹类型参数?

时间:2014-04-08 01:02:46

标签: c# types type-parameter

如果我有一个C#类:

public class MyFactory<TWidget, TGadget, TGizmo, TThing> 
    where TWidget: IWidget
    where TGadget: IGadget
    where TGizmo: IGizmo
    where TThing: IThing, new()
    {
      public TThing CreateThing(ThingModel model) {
        // create Thing here
      }
    }

有没有办法将这些类型打包成更短的东西?换句话说,就像这样:

ThingModel model = this.ThingModel;
TTypeList typeList = this.TypeList; // the list wraps TNativeWidget, TNativeGadget, TNativeGizmo, and TNativeThing
MyFactory<TTypeList> factory = new Factory(typeList);
TNativeThing thing = factory.CreateThing(model);

0 个答案:

没有答案