类中的泛型继承 [英] Generic inheritance in a class

查看:62
本文介绍了类中的泛型继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用两个继承级别的类,例如:

I am trying to create a class that uses two levels of inheritance as such:

public class QuickDateTokenParcer<TQuickDateRelative, TUserInputOrderAdjustment>
where TQuickDateRelative : AbstractQuickDateRelative<TUserInputOrderAdjustment>, new() 
where TUserInputOrderAdjustment : AbstractUserInputOrderAdjustment, new()



可以,除非我真的不喜欢这样指定它:



This would be OK except I really do not like specifying it like:

var dic = new QuickDateTokenParcer<QuickDateRelativePast
      <UserInputOrderAdjustmentMdy>, UserInputOrderAdjustmentMdy>(
	"QuickDateStrings.xml", DateTime.Now);



我显然可以解决这个问题,但希望能够执行以下操作:



I can obviously get around this, but would like be able to do the following:

var dic = new QuickDateTokenParcer<QuickDateRelativePast
      <UserInputOrderAdjustmentMdy>>(
	"QuickDateStrings.xml", DateTime.Now);



或以下



or the following

var dic = new QuickDateTokenParcer<QuickDateRelativePast,
      UserInputOrderAdjustmentMdy>(
	"QuickDateStrings.xml", DateTime.Now);

推荐答案

总有:
using QuickDateRelativePastMdy = QuickDateRelativePast<UserInputOrderAdjustmentMdy>;
//...
var dic = new QuickDateTokenParcer<QuickDateRelativePastMdy,
                                   UserInputOrderAdjustmentMdy>
                   ("QuickDateStrings.xml", DateTime.Now);


这篇关于类中的泛型继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆