zoukankan      html  css  js  c++  java
  • 反射类的一些基本用法

       /// <summry>
            /// 反射的命名空间和类名
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe1(T value)
            {
                Type type1 = value.GetType();
                string a = type1.FullName;
                return a;
            }
    
            /// <summary>
            /// 反射所有的属性
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe2(T value)
            {
                Type type1 = value.GetType();
                PropertyInfo[] a = type1.GetProperties();
                string allvalue = "";
                foreach (var item in a)
                {
                    allvalue += item.Name + ",";
                }
                string allvalue1 = allvalue.TrimEnd(',');
                return allvalue1;
            } 
    
            /// <summary>
            /// 反射所有属性值
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe3(T value)
            {
                Type type1 = value.GetType();
                PropertyInfo[] a = type1.GetProperties();
                string allvalue = "";
                foreach (var item in a)
                {
                    allvalue+=item.GetValue(value, null).ToString()+",";
                }
               string allvalue1= allvalue.TrimEnd(',');
               return allvalue1;
            }
    
    
            /// <summary>
            /// 反射所有属性的类型
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe4(T value)
            {
                Type type1 = value.GetType();
                PropertyInfo[] a = type1.GetProperties();
                string allvalue = "";
                foreach (var item in a)
                {
                    allvalue += item.PropertyType + ",";
                }
                string allvalue1 = allvalue.TrimEnd(',');
                return allvalue1;
            }
    
            /// <summary>
            /// 反射所有的公共构造方法
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe5(T value)
            {
                Type type1 = value.GetType();
                ConstructorInfo[] a = type1.GetConstructors();
                string allvalue = "";
                foreach (var item in a)
                {
                    allvalue += item.Name.ToString() + ",";
                }
                string allvalue1 = allvalue.TrimEnd(',');
                return allvalue1;
            }
    
            /// <summary>
            /// 反射所有的方法
            /// </summary>
            /// <param name="value">对象</param>
            /// <returns></returns>
            public string fanshe6(T value)
            {
                Type type1 = value.GetType();
                MethodInfo[] a = type1.GetMethods(); 
                string allvalue = "";
                foreach (var item in a)
                {
                    allvalue += item.Name.ToString() + ",";
                }
                string allvalue1 = allvalue.TrimEnd(',');
                return allvalue1;
            }
    
  • 相关阅读:
    EasyUI-datagrid-自动合并单元格(转)
    js中格式化时间字符串
    ext 3.2 tree 在IE10中点击事件失效的bug
    C#中修改Dll文件 (反编译后重新编译)
    GridView内容<br />换行
    使用Aspose.Words把 word转成图片
    判断移动设备访问自动跳转到移动版页面
    jquery mobile界面数据刷新
    Ubuntu16.04下安装Visual Studio Code
    npm 安装vue 报错Failed at the chromedriver@2.46.0 install script 'node install.js'
  • 原文地址:https://www.cnblogs.com/srfree/p/3310367.html
Copyright © 2011-2022 走看看