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

  • 相关阅读:
    IOS创建Button简单实例
    IOSActionSheet、AlertView、Slider、Switch的简单使用
    IOS翻转注意
    [教程]iOS 4 开发的好东西 (资料)url
    Proxy和Decorator模式
    Using JNDI connecting DB
    影片“One Day”,还不错
    Minabased TCP server examples
    MySQL vs. Oracle on sequence
    Java DB and JDBC(Embedded Derby)
  • 原文地址:https://www.cnblogs.com/kexb/p/3645141.html
Copyright © 2011-2022 走看看