unit RttiTypeHelper;
interface
uses System.Rtti;
type
TRttiTypeHelper =
class helper
for TRttiType
private const
Para_inheritsFromType_includeCurrent = True;
public
function inheritsFromType(
const baseType: TRttiType;
const includeCurrent: Boolean = Para_inheritsFromType_includeCurrent
): Boolean;
overload;
function inheritsFromType(
const baseClass: TClass;
const includeCurrent: Boolean = Para_inheritsFromType_includeCurrent
): boolean;
overload;
end;
implementation
function TRttiTypeHelper.inheritsFromType(
const baseType: TRttiType;
const includeCurrent: Boolean = Para_inheritsFromType_includeCurrent
): Boolean;
var
currentClassType: TRttiType;
begin
Result := False;
if not includeCurrent
then
currentClassType := self.baseType
else
currentClassType := self;
while (
not Result)
and Assigned(currentClassType)
do begin
if currentClassType = baseType
then
Result := True;
currentClassType := currentClassType.baseType;
end;
end;
function TRttiTypeHelper.inheritsFromType(
const baseClass: TClass;
const includeCurrent: Boolean = Para_inheritsFromType_includeCurrent
): Boolean;
var
rttiContext: TRttiContext;
begin
rttiContext := TRttiContext.Create();
Result := inheritsFromType( rttiContext.GetType(baseClass), includeCurrent);
end;
end.