考虑一个带有一个参数的类装饰器:
@TableName("Orders")
export class Order {
// ...
}
装饰器定义为:
import "reflect-metadata";
const classDecoratorKey = Symbol.for("custom:TableName");
export function TableName(tableName: string): ClassDecorator {
return (constructor: Function) => {
Reflect.defineMetadata(classDecoratorKey, tableName, constructor);
}
}
export function getTableName(target: any): string {
return Reflect.getMetadata(classDecoratorKey, target.constructor, "class") || "";
}
我现在希望得到@TableName 值“Orders”。如何检索类装饰器的参数值?
let order = new Order();
getTableName(order); // "" but expected "Orders"