如何获取方法链接泛型类型的 TRTTIType

Bit*_*man 2 delphi rtti delphi-10.3-rio

我使用德尔福10.3。这是获取对应实例变量的一种例程TRTTIType。但是有什么方法可以填补此处标记为“缺少代码”的空白:

function getGenericTypeName<T> : string;
var
  ctx : TRTTIContext;
  aRT : TRTTIType;
begin
  ctx := TRTTIContext.Create;
  try
    aRT := *** missing code for T *** // Get the TRTTIType for type T
    result := aRT.Name;
  finally
    ctx.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

Dav*_*nan 5

您正在寻找

ctx.GetType(TypeInfo(T))
Run Code Online (Sandbox Code Playgroud)