加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi Spring框架注册泛型类型

发布时间:2020-12-15 09:26:13 所属栏目:大数据 来源:网络整理
导读:使用Delphi Spring框架,是否可以使用GlobalContainter注册泛型类型?我正在尝试做这样的事情: TMyBaseType = classprotected FName: string; function GetName: string; virtual; procedure SetName(Value: string); virtual;public property Name: string
使用Delphi Spring框架,是否可以使用GlobalContainter注册泛型类型?我正在尝试做这样的事情:

TMyBaseType = class
protected
  FName: string;
  function GetName: string; virtual;
  procedure SetName(Value: string); virtual;
public
  property Name: string read GetName write SetName;
end;

TMyFirstThing = class(TMyBaseType)
protected
  function GetName: string; override;
end;

TMySecondThing = class(TMyBaseType)
protected
  procedure SetName(Value: string); override;
end;

TMyGenericType<T: TMyBaseType> = class
public
  procedure DoSomethingWithIt(AObject: T);
  function GetTheSomethingsName(AObject: T): string;
end;

// I now want to be able to use the ServiceLocator to get me an instance
// such as TMyGenericType<TMyFirstThing> or TMyGenericType<TMySecondThing>
// but I cannot figure out how to register TMyGenericType<>

......

initialization
  GlobalContainer.RegisterType<TMyGenericType<>>;
// this line fails with the messages:
// [DCC Error] E2251 Ambiguous overloaded call to 'RegisterType'
// [DCC Error] E2531 Method 'RegisterType' requires explicit type argument(s)

我不确定我想要做的是否可行,或者是否有更好的/替代的方法来做到这一点?
我正在使用Delphi 2010和最新的Spring4D框架. (我也有Delphi XE5,但由于第三方库,该项目本身仍然是2010年).
任何想法或建议将非常感激.

解决方法

Delphi没有未绑定(或开放)泛型类型(类似于TMyGenericType<&gt ;. 在您的情况下,您必须单独注册每个封闭的构造泛型类型(TMyGenericType< TMyFirstThing>,TMyGenericType< TMySecondThing>,…).

关于C#,C和Delphi中泛型差异的更多信息:
http://blogs.teamb.com/craigstuntz/2009/10/01/38465/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读