当前位置:编程学习 > C#/ASP.NET >>

使用反射获取类的静态属性值

public class GetConn
    {
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static string connString
        {
            get
            {
                return ConfigurationManager.AppSettings["connString"];
            }
        }

        public static string CrmConnString
        {
            get
            {
                return ConfigurationManager.AppSettings["CrmConnString"];
            }
        }

        public static string QhdConnString
        {
            get
            {
                return ConfigurationManager.AppSettings["QhdConnString"];
            }
        }

        public static string BjConnString
        {
            get
            {
                return ConfigurationManager.AppSettings["BjConnString"];
            }
        }

        public static string ZzConnString
        {
            get
            {
                return ConfigurationManager.AppSettings["ZzConnString"];
            }
        }
    }

方法:

return typeof(GetConn).GetProperty("ConnString").GetValue(null, null).ToString();
    
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,