/*adorners are simple to understand that attribute in C # can be decorated with classes, functions, interrogation characters, attributes, parameters on the syntax @xxx adorners are actually a function @xxx there will be a functions xxx multiple adorners can be used to decorate a declaration, @f @g ARG or on multiple lines @f @g x Such a combination the final result will be the execution order of the F (g (x)) Adorner 1, the parametric adorner, followed by the method adorner, the accessor adorner, or the property adorner applied to each instance member. 2. Parameter adorner, then the method adorner, the accessor adorner, or the property adorner applied to each static member. 3. The parameter adorner is applied to the constructor. 4. Class decorators are applied to classes. Adorners are currently experimental, and may be removed in a later version. The default is not to turn on the adorner function we manually configure Experimentaldecorators to Tsconfig to True*//** * A simple method adorner parameter target is a constructor for a class for static members, and for instance members is the class's prototype object PropertyKey member name here is the method descriptor member Property descriptor If the method adorner returns a value, it is used as the method's shape descriptor*/function f () {//when calling the Class C method methods, the order in which they are executed isConsole.log ("f (): evaluated");//--1 returnfunction (target, PropertyKey:string, Descriptor:propertydescriptor) {Console.log ("f (): called");//--4}}function g () {Console.log ("g (): Evaluated");//--2 returnfunction (target, PropertyKey:string, Descriptor:propertydescriptor) {Console.log ("g (): Called");//--3 }}classC {@f () @g () method () {}//--5}/*class Adorner parameter constructor constructor class adorner is declared before the class declaration, and if a value (new constructor) is returned, it replaces the declaration of the class with the provided constructor*/function Classdecorator (constructor:function) {} @classDecoratorclassB {Constructor (message:string) { }}/*Accessor adorners are used to decorate get; The Set needs to be aware of decorating the first accessor, which is the default adornment get Set target is the constructor for a class for static members, and for instance members is the class's prototype object PropertyKey member name here is Method descript Property descriptor for an or member if the accessor adorner returns a value, it is used as the property descriptor for the method. */function Decorator (Target:any, PropertyKey:string, Descriptor:propertydescriptor) {}classD {Private_x:number; @DecoratorGetX () {return This. _x}; SetX (Value:number) { This. _x =value};}/*The property Adorner parameter target is the constructor of the class for static members, and is the prototype object for the class for instance members. The name of the PropertyKey member. If the accessor adorner returns a value, it is used as the property descriptor for the method. *//*The parameter adorner target is the constructor of the class for static members and is the prototype object for the class for instance members. The name of the PropertyKey member. The index of the Parameterindex parameter in the function argument list. Parameter decorators can only be used to monitor whether a method's parameters are passed in, and cannot get the value, the number of the adorner's return value is ignored. */function Argdecorator (target:object, PropertyKey:string|symbol, Parameterindex:number) {}function Fun (@argDecorator name:string) {}
TypeScript Sketch-Decorator