Tôi có một lớp học với các đạo cụ đã xuất bản mà tôi sắp xếp thành XML.Nhận giá trị attribue của bất động sản cụ thể
MyAttr = class(TCustomAttribute)
private
FName: string;
public
constructor Create(const Name: string);
property Name: string read FName write FName;
end;
MyClass = class(TPersistent)
private
FClassCaption: string;
published
[MyAttr('Class')]
property ClassCaption: string read FClassCaption write FClassCaption;
end;
Vì kích thước XML là rất quan trọng, tôi sử dụng thuộc tính để đặt tên ngắn hơn cho thuộc tính (nghĩa là tôi không thể xác định thuộc tính có tên 'Lớp'). serialization thực hiện theo cách sau:
lPropCount := GetPropList(PTypeInfo(Obj.ClassInfo), lPropList);
for i := 0 to lPropCount - 1 do begin
lPropInfo := lPropList^[i];
lPropName := string(lPropInfo^.Name);
if IsPublishedProp(Obj, lPropName) then begin
ItemNode := RootNode.AddChild(lPropName);
ItemNode.NodeValue := VarToStr(GetPropValue(Obj, lPropName, False));
end;
end;
tôi cần điều kiện như: nếu tài sản được đánh dấu bằng MyAttr, nhận được "MyAttr.Name" thay vì "lPropInfo^.name".