delphi – 如何在TVirtualInterface TVirtualInterfaceInvokeEve
发布时间:2020-12-15 04:08:52 所属栏目:大数据 来源:网络整理
导读:我如何在TVirtualInterface类的OnInvoke方法中获得Method:TRttiMethod的所有权属性? 我有这个界面: IPerson = interface(IInvokable) ['{45CE428C-F880-4D61-A2C1-0F3CB47130B5}'] procedure SetName(const Value: string); function GetName(): string;
我如何在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; 解决方法
不幸的是,你做不到.没有为接口属性生成RTTI,因此没有任何内容可以附加到自定义属性.即使没有警告,您对interface属性的修饰也没有任何效果.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |