zoukankan      html  css  js  c++  java
  • .net中反射技术的应用

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;

    namespace WebApplication2 {    

                public partial class WebForm1 : System.Web.UI.Page  

               {       

      protected void Page_Load(object sender, EventArgs e)   

          {

                user u = new user() { name = "zhangsan", age = 33, money = new List<int>() {1,2,3,4,5 } };  

               string aa=Server.MapPath("/user.cs");

              string bb = Assembly.LoadFile(Server.MapPath("/bin/WebApplication21.dll")).FullName.ToString();

             string cc= this.GetType().Assembly.FullName.ToString();  

            Type t = typeof(user);   

           FieldInfo[] fields =t.GetFields (BindingFlags.Public);  

          System.Text.StringBuilder parms = new System.Text.StringBuilder();  

           parms.Append("age");

           parms.Append("name");       

            parms.Append("hh");

           Dictionary<string, FieldInfo> dic = new Dictionary<string, FieldInfo>();

               fields.ToList().ForEach(c=>dic.Add(c.Name,c));

               foreach (FieldInfo field in fields)            {                FieldInfo  f = field;               object newValue= f.GetValue(u);               f.SetValue(u, newValue);            }         }     } }

  • 相关阅读:
    POJ 1019 组合计数
    POJ 3252 组合计数
    SPJ 与 Student 数据库的创建于数据插入
    POJ 1496 POJ 1850 组合计数
    Java常用类库--大数处理类
    POJ 2492 并查集应用的扩展
    POJ 3268 双向Dijkstra
    线段树(带删除节点)
    西工大10级保研机试 柱状图
    KMP专场 POJ
  • 原文地址:https://www.cnblogs.com/kexb/p/3645141.html
Copyright © 2011-2022 走看看