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);            }         }     } }

  • 相关阅读:
    JSJ—类与对象
    JSJ—案例谈面向对象
    实现简单神经网络
    SSM+Netty项目结合思路
    SSM-Netty实现软硬件通信,真实项目案例
    Netty实战十四之案例研究(一)
    Netty实战十三之使用UDP广播事件
    Netty实战十一之预置的ChannelHandler和编解码器
    Netty实战十二之WebSocket
    Netty实战十之编解码器框架
  • 原文地址:https://www.cnblogs.com/kexb/p/3645141.html
Copyright © 2011-2022 走看看