Browse Source

* Patch from Henrique Werlang to implement generic AsType<T>()

michael 4 years ago
parent
commit
4cbd08c400
1 changed files with 6 additions and 0 deletions
  1. 6 0
      packages/rtl/rtti.pas

+ 6 - 0
packages/rtl/rtti.pas

@@ -41,6 +41,7 @@ type
     property TypeInfo: TTypeInfo read FTypeInfo;
     property TypeInfo: TTypeInfo read FTypeInfo;
 
 
     property IsEmpty: boolean read GetIsEmpty; // check if nil or undefined
     property IsEmpty: boolean read GetIsEmpty; // check if nil or undefined
+    generic function AsType<T>: T;
     function IsObject: boolean;
     function IsObject: boolean;
     function AsObject: TObject;
     function AsObject: TObject;
     function IsObjectInstance: boolean;
     function IsObjectInstance: boolean;
@@ -539,6 +540,11 @@ begin
     Result:=FTypeInfo.Kind;
     Result:=FTypeInfo.Kind;
 end;
 end;
 
 
+generic function TValue.AsType<T>: T;
+begin
+  Result := T(AsJSValue)
+end;
+
 generic class function TValue.From<T>(const Value: T): TValue;
 generic class function TValue.From<T>(const Value: T): TValue;
 begin
 begin
   Result := Make(System.TypeInfo(T), Value);
   Result := Make(System.TypeInfo(T), Value);