如果我有一个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);