首页 > 代码库 > Spring.net ObjectWrapper对象的包装(反射机制)有点明晰方便
Spring.net ObjectWrapper对象的包装(反射机制)有点明晰方便
Company c = new Company(); List<PropertyInfo> ps = c.GetType().GetProperties().ToList(); var pname = ps.First(x => x.Name == "Name"); IObjectWrapper owComp = new ObjectWrapper(c); // setting the company name... pname.SetValue(c, "134"); owComp.SetPropertyValue("Name", "KEXB."); // can also be done like this... PropertyValue v = new PropertyValue("name", "Salina Inc1."); owComp.SetPropertyValue(v); // ok, let‘s create the director and bind it to the company... Employee don = new Employee(); IObjectWrapper owDon = new ObjectWrapper(don); owDon.SetPropertyValue("salary", 99); owDon.SetPropertyValue("name", "Don Fabrizio"); owComp.SetPropertyValue("managingDirector", don); // retrieving the salary of the ManagingDirector through the company float salary = (float)owComp.GetPropertyValue("ManagingDirector.salary");
Spring.net ObjectWrapper对象的包装(反射机制)有点明晰方便
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。