我如何在TVirtualInterface类的OnInvoke方法中获得Method:TRttiMethod的所有权属性?
我有这个界面:
IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); function GetName(): string; [TEntityField('Field Name Here')] property Name: string read GetName write SetName; end;
而这堂课:
type TVirtualEntity<T: IInvokable> = class(TVirtualInterface) public constructor Create(); reintroduce; overload; end; constructor TVirtualEntity<T>.Create; begin inherited Create(TypeInfo(T)); Self.OnInvoke := procedure(Method: TRttiMethod; const Args: TArray<TValue>; out Result: TValue) var attributes: TArray<TCustomAttribute>; attributesManager: TAttributesManager; entityFieldAttribute: TEntityField; begin attributesManager := TAttributesManager.Create(Method.GetAttributes); try if attributesManager.HasAttribute<TEntityField>() then begin Result := attributesManager.GetAttribute<TEntityField>.FieldName; end; finally attributesManager.Free; end; end; end;
我想获得方法的TRttiProperty:TRttiMethod,但是如何?
如果我将界面更改为:
IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); [TEntityField('Field Name Here')] function GetName(): string; property Name: string read GetName write SetName; end;
IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); function GetName(): string; [TEntityField('Field Name Here')] property Name: string read GetName write SetName; end;
解决方法
原文地址:https://www.jb51.cc/delphi/102121.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。