import 'reflect-metadata' import { singleton } from './singleton' const noJsonMetadataKey = ('noJsonSet') @singleton export class NoJsonClass { private noJsonPropSet: Set = new Set() public addKey(className: string, propertyKey: string) { this.noJsonPropSet.add(className+'_'+propertyKey) } public checkExist(className: string, propertyKey: string) { return this.noJsonPropSet.has(className+'_'+propertyKey) } } /** * 在不需要toJson方法输出的字段上加上 @noJson * @return {{(target: Function): void, (target: Object, propertyKey: (string | symbol)): void}} */ export function noJson() { // return Reflect.metadata(noJsonMetadataKey, !0) return function(target: Object, propertyKey: string) { console.log(target) new NoJsonClass().addKey(target.constructor.name, propertyKey) } } export function checkJson(target: any, propertyKey: string) { return !new NoJsonClass().checkExist(target.constructor.modelName, propertyKey) }