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

  • 相关阅读:
    CF919F A Game With Numbers
    CF1005F Berland and the Shortest Paths
    CF915F Imbalance Value of a Tree
    CF1027F Session in BSU
    CF1029E Tree with Small Distances
    CF1037E Trips
    CF508E Arthur and Brackets
    CF1042F Leaf Sets
    [HNOI2012]永无乡
    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理
  • 原文地址:https://www.cnblogs.com/kexb/p/3645141.html
Copyright © 2011-2022 走看看