// 假设 IPage 接口定义如下 interface IPage {} // 假设 TradeModel 类型定义如下 interface TradeModel {} // 定义一个全局对象来存储附加属性的值 const attachedProperties = new WeakMap(); function getAttachedProperty(obj: object, propertyName: string): T | undefined { const properties = attachedProperties.get(obj); return properties?.[propertyName]; } function setAttachedProperty(obj: object, propertyName: string, value: any) { let properties = attachedProperties.get(obj); if (!properties) { properties = {}; attachedProperties.set(obj, properties); } properties[propertyName] = value; } export class PageHelper { // OwnerPage 附加属性 static get OwnerPageProperty() { return "OwnerPage"; } static GetOwnerPage(d: object): IPage | undefined { return getAttachedProperty(d, this.OwnerPageProperty); } static SetOwnerPage(d: object, value: IPage) { setAttachedProperty(d, this.OwnerPageProperty, value); } // ViewStateData 附加属性 static get ViewStateDataProperty() { return "ViewStateData"; } static GetViewStateData(obj: object): Record | undefined { return getAttachedProperty>(obj, this.ViewStateDataProperty); } static SetViewStateData(obj: object, value: Record) { setAttachedProperty(obj, this.ViewStateDataProperty, value); } // TradeModel 附加属性 static get TradeModelProperty() { return "TradeModel"; } static GetTradeModel(obj: object): TradeModel | undefined { return getAttachedProperty(obj, this.TradeModelProperty); } static SetTradeModel(obj: object, value: TradeModel) { setAttachedProperty(obj, this.TradeModelProperty, value); } }