zoukankan      html  css  js  c++  java
  • 遍历对象属性,成员,方法的方法

    using System;
    using System.Reflection;
    using System.Web;
    
    namespace WebApplication5
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                HttpRuntime hr = new HttpRuntime();
                DisplayValues(hr);
            }
            public void DisplayValues(object o)
            {
                Type type = o.GetType();
                outPut("<hr>Methods<br>");
                MethodInfo[] methodInfos = type.GetMethods();
                foreach (MethodInfo m in methodInfos)
                {
                    outPut(m.Name);           
                }
    
                outPut("<hr>Fields<br>");
                FieldInfo[] fieldInfos = type.GetFields();
                foreach (FieldInfo f in fieldInfos)
                {
                    outPut(f.Name + ": " + f.GetValue(null).ToString());
                }
    
                outPut("<hr>Properties<br>");
                PropertyInfo[] propertyInfos = type.GetProperties();
                foreach (PropertyInfo p in propertyInfos)
                {
                    outPut(p.Name + ": " + p.GetValue(null, null).ToString());
                }
            }
            public void outPut(string s)
            {
                ltl1.Text += s + "<br>";
            }
        }
    }
  • 相关阅读:
    JavaScript
    CSS
    HTML5&CSS
    I2C mux和复杂拓扑
    如何实例化I2C设备
    SMBus 协议
    I2C 协议
    I2C和SMBus简介
    ubuntu20.04系统下更新Raspberry Pi4的DTB
    通过configfs配置的Linux USB gadget
  • 原文地址:https://www.cnblogs.com/JingG/p/3108503.html
Copyright © 2011-2022 走看看