I'm using reflect-metadata
with typescript. I composed my own property decorator and it's called Field
. How to get list of fields/properties, which are decorated by Field
, of any type. For example: I want to get ProductID
, ProductName
field with their metadata from class Product
/shown in below/.
import 'reflect-metadata';
export const FIELD_METADATA_KEY = 'Field';
export interface FieldDecorator {
field?: string;
title?: string;
type?: string;
}
export function Field(field: FieldDecorator) {
return Reflect.metadata(FIELD_METADATA_KEY, field);
}
export class Product {
@Field({
title: 'Product Id'
})
ProductID: string;
@Field({
title: 'Product Name',
type: 'text'
})
ProductName: string;
UnitPrice: number; //not decorated
}