-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-GeneralDecorator.ts
101 lines (73 loc) · 2.49 KB
/
08-GeneralDecorator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright 2023 Angus.Fenying <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import $Decorators from '../lib';
const test = $Decorators.createGeneralDecorator({
class(c): void {
console.log(`Decorated class ${c.name}`);
},
ctorParameter(c, i): void {
console.log(`Decorated class ${c.name}'s constructor parameters[${i}]`);
},
property(c, n): void {
console.log(`Decorated class ${c.constructor.name}'s member property "${n as string}"`);
},
staticProperty(c, n): void {
console.log(`Decorated class ${c.name}'s static property "${n as string}"`);
},
method(c, n): void {
console.log(`Decorated class ${c.constructor.name}'s member method "${n as string}"`);
},
staticMethod(c, n): void {
console.log(`Decorated class ${c.name}'s static method "${n as string}"`);
},
methodParameter(c, n, i): void {
console.log(`Decorated class ${c.constructor.name}'s member method "${n as string}" parameters[${i}]`);
},
staticMethodParameter(c, n, i): void {
console.log(`Decorated class ${c.name}'s static method "${n as string}" parameters[${i}]`);
}
});
@test
class DemoGeneralDecorator {
@test
private _value: number;
@test
public static _staticValue: number;
public constructor(@test v: number) {
this._value = v;
}
@test
public print(@test i: number): void {
console.log(`Test: ${this._value + i}`);
}
@test
public static greet(@test person: string): void {
console.log('Hello', person);
}
}
new DemoGeneralDecorator(233).print(333);
const mark = $Decorators.createPropertyDecorator(function() {});
const gMark = $Decorators.createGeneralDecorator({ property() {}, staticProperty() {} });
class A {
@mark
public a!: string;
public b!: string;
@mark
public c!: string;
@gMark
public static d: string;
}
console.log($Decorators.getOwnPropertyNames(A).join(','));