Delphi Spring框架注册泛型类型



使用Delphi Spring框架,是否有可能与globalcontainer注册泛型类型?我想做这样的事情:

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<>)。

在您的情况下,您必须单独注册每个封闭构造泛型(TMyGenericType<TMyFirstThing>, TMyGenericType<TMySecondThing>,…)。

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

相关内容

  • 没有找到相关文章

最新更新