mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-25 17:19:04 +02:00
* Reworked patch from Henrique Gottardo with additional function to get custom attribute (merge request pas2js rtti.pas)
This commit is contained in:
parent
0a4390f54a
commit
882044c2e0
@ -118,6 +118,10 @@ type
|
||||
destructor Destroy; override;
|
||||
|
||||
function GetAttributes: TCustomAttributeArray;
|
||||
generic function GetAttribute<T: TCustomAttribute>: T;
|
||||
function GetAttribute(const Attribute: TCustomAttributeClass): TCustomAttribute;
|
||||
generic function HasAttribute<T: TCustomAttribute>: Boolean;
|
||||
function HasAttribute(const Attribute: TCustomAttributeClass): Boolean;
|
||||
|
||||
property Attributes: TCustomAttributeArray read GetAttributes;
|
||||
property Handle: Pointer read FHandle;
|
||||
@ -1638,6 +1642,34 @@ begin
|
||||
Result := FAttributes;
|
||||
end;
|
||||
|
||||
function TRttiObject.GetAttribute(const Attribute: TCustomAttributeClass): TCustomAttribute;
|
||||
var
|
||||
CustomAttribute: TCustomAttribute;
|
||||
|
||||
begin
|
||||
Result := nil;
|
||||
|
||||
for CustomAttribute in GetAttributes do
|
||||
if CustomAttribute is Attribute then
|
||||
Exit(CustomAttribute);
|
||||
end;
|
||||
|
||||
generic function TRttiObject.GetAttribute<T>: T;
|
||||
|
||||
begin
|
||||
Result := T(GetAttribute(TCustomAttributeClass(T.ClassType)));
|
||||
end;
|
||||
|
||||
function TRttiObject.HasAttribute(const Attribute: TCustomAttributeClass): Boolean;
|
||||
begin
|
||||
Result := GetAttribute(Attribute) <> nil;
|
||||
end;
|
||||
|
||||
generic function TRttiObject.HasAttribute<T>: Boolean;
|
||||
begin
|
||||
Result := HasAttribute(TCustomAttributeClass(T.ClassType));
|
||||
end;
|
||||
|
||||
{ TRttiNamedObject }
|
||||
|
||||
function TRttiNamedObject.GetName: string;
|
||||
|
Loading…
Reference in New Issue
Block a user