Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from gleisonpauloc/master
Browse files Browse the repository at this point in the history
Include validation to methods
  • Loading branch information
EduardoGrtt authored Oct 31, 2018
2 parents 66a6313 + 8fe1fd2 commit 04e2057
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/PerformanceDiagnostics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ TPerformanceDiagnostics = class(TInterfacedObject, IPerformanceDiagnostics)
strict private
FInterceptor: IMethodInterceptor;
FInterceptedList: TInterceptedList;
FObjectClassType: TClass;
private
procedure DoOnBefore(_AInstance: TObject; _AMethod: TRttiMethod; const _AArgs: TArray<TValue>; out _ADoInvoke: Boolean; out _AResult: TValue);
procedure DoOnAfter(_AInstance: TObject; _AMethod: TRttiMethod; const _AArgs: TArray<TValue>; var _AResult: TValue);
Expand All @@ -34,13 +35,21 @@ implementation
{ TPerformanceDiagnostics }

function TPerformanceDiagnostics.Add(_AMethodName: string): IPerformanceDiagnostics;
var
RttiContext: TRttiContext;
RttiMethod: TRttiMethod;
begin
RttiMethod := RttiContext.GetType(FObjectClassType).GetMethod(_AMethodName);
if not (Assigned(RttiMethod) and (RttiMethod.DispatchKind = dkVtable)) then
raise Exception.CreateFmt('"%s" is not a virtual method.' , [_AMethodName]);

List.Add(_AMethodName, Default(TStopwatch));
Result := Self;
end;

constructor TPerformanceDiagnostics.Create(_AObject: TObject);
begin
FObjectClassType := _AObject.ClassType;
FInterceptor := TMethodInterceptor.New(_AObject, DoOnBefore, DoOnAfter);
end;

Expand Down

0 comments on commit 04e2057

Please sign in to comment.