zoukankan      html  css  js  c++  java
  • .net 取得类的属性、方法、成员及通过属性名取得属性值

    //自定义的类
    model m = new model();

    //取得类的Type实例
    //Type t = typeof(model); 

    //取得m的Type实例
    Type t = m.GetType(); 

    string className = t.Name +" "; 

    //获取所有方法 
    System.Reflection.MethodInfo[] methods =t.GetMethods(); 

    //获取所有成员
    System.Reflection.MemberInfo[] members =t.GetMembers(); 

    //获取所有属性 
    System.Reflection.PropertyInfo[] properties =t.GetProperties(); 

    //取得类的属性名并获取属性值
    foreach (System.Reflection.PropertyInfo s int.GetProperties())
    {
        className += s.Name + ":" +m.GetType().GetProperty(s.Name).GetValue(m, null).ToString() +" ";
    }
  • 相关阅读:
    python023
    python019
    python018
    python017
    python016
    python013
    python012
    数据库,盘它!!!!
    网络编程
    面向对象简述
  • 原文地址:https://www.cnblogs.com/dcrenl/p/4041127.html
Copyright © 2011-2022 走看看