feat: 反射工具新增set方法

merge/1/MERGE
coding 2017-10-14 07:32:00 +00:00
parent 21cca40534
commit 57554fa644
1 changed files with 10 additions and 0 deletions

View File

@ -17,6 +17,7 @@ function Reflect(obj) {
this.obj = obj;
this.class = obj.class;
}
this.field = function (name) {
try {
// Try getting a public field
@ -59,6 +60,15 @@ function Reflect(obj) {
return arguments.length === 1 ? this.field(arguments[0]) : this.obj;
};
this.set = function (name, value) {
try {
this.class.getField(name).set(this.obj, value);
} catch (ex) {
accessible(this.class.getDeclaredField(name)).set(this.obj, value);
}
return this;
}
this.create = function () {
var param = Array.prototype.slice.call(arguments);
return on(declaredConstructor(this.class, param).newInstance(param));