zoukankan      html  css  js  c++  java
  • c# 反射类字段

        //在wpf中动态绘制Grid布局控件中值 需要来动态获取类中的字段数来自动生成Grid列数或者行数,
        public class models
        {
            public Label name { get; set; }
            public Label age { get; set; }       
            public GifImage gif { get; set; }
            public Image img { get; set; }
            public Button btn { get; set; }
        }


    //这是需要反射的类,主要是用代码来获取该类中的所有字段
               Type t = typeof(models); //获取类的类型
               //类中字段的集合
               PropertyInfo[] info = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
               foreach (PropertyInfo i in info)
               {
                   string name = i.Name;  //获取类中字段的名称 
                //    clomn = new  ColumnDefinition ();
                //    grid.ColumnDefinitions.Add(clomn);           
                 
               }
    //***over
    //*********************************
              //反射所有属性 
                Type t = typeof(models);
                MethodInfo[] info = t.GetMethods();
                foreach (MethodInfo i in info)
                {
                    
                }

  • 相关阅读:
    FFT入门
    FJOI省队集训 chessboard
    FJOI省队集训 florida
    树上莫队
    NOIP2015 Revenge
    APIO2013 tasksauthor
    油漆门
    一些字符串有关的题目
    字符串题模板集合
    sg函数与博弈论2
  • 原文地址:https://www.cnblogs.com/tianyiwuying/p/4694500.html
Copyright © 2011-2022 走看看