我有一门带有已出版的推进剂的班子,我将其编成XML。
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;
Since XML size is crucial, I use attributes to give shorter name for property (i.e I can t define a property named Class ). Serialization implemented the following way:
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;
我需要这样的条件:如果以MyAttr为标志的财产获得“MyAttr.Name”,而不是“lPropInfo^.Name”。