我如何在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;