Пример #1
0
        /// <summary>
        /// 将指定类的静态全局变量设置值
        /// </summary>
        /// <param name="classFullName">类的完整名称如:callcenter.GlobalConfig</param>
        /// <param name="data">指定Key-Value值</param>
        public static void SetPublicStaticProperties(Type classType, Hashtable data)
        {
            PropertyInfo propertyInfo;

            foreach (DictionaryEntry property in data)
            {
                propertyInfo = classType.GetProperty(property.Key.ToString(), BindingFlags.Public | BindingFlags.Static);
                if (propertyInfo != null)
                {
                    if (propertyInfo.PropertyType.Equals(typeof(Boolean)))
                    {
                        bool value = property.Value.ToString().ToLower() == "true" ? true : false;
                        propertyInfo.SetValue(property.Key, value, null);
                    }
                    else if (propertyInfo.PropertyType.Equals(typeof(Int32)))
                    {
                        if (UtilNumber.IsDigit(property.Value.ToString()))
                        {
                            int value = int.Parse(property.Value.ToString());
                            propertyInfo.SetValue(property.Key, value, null);
                        }
                    }
                    else
                    {
                        propertyInfo.SetValue(property.Key, property.Value, null);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 转换数据类型
        /// </summary>
        /// <param name="oldType">原数据类型</param>
        /// <returns>新数据类型</returns>
        private static string[] Enum_ColumnDefine(string column_comment)
        {
            string[]      result = null;
            List <string> resultL;
            List <string> enumL = new List <string>();
            List <Dictionary <string, string> > commentsDicL;
            Dictionary <string, string>         commentsDic;
            string m_comment;

            string[] c_comments = column_comment.Split(new char[2] {
                '\r', '\n'
            }, StringSplitOptions.RemoveEmptyEntries);

            if ((c_comments != null) && (c_comments.Length > 0))
            {
                string[] c_comment;
                string   comment_c, comment_v;
                commentsDicL = new List <Dictionary <string, string> >();
                resultL      = new List <string>();
                foreach (string comment in c_comments)
                {
                    m_comment = comment;
                    if (comment.Contains(":"))
                    {
                        m_comment = comment.Replace(":", ":");
                    }
                    c_comment = Regex.Split(m_comment, ":");
                    if ((c_comment != null) && (c_comment.Length == 2))
                    {
                        commentsDic = new Dictionary <string, string>();
                        comment_v   = c_comment[0];
                        comment_c   = c_comment[1];
                        if (UtilNumber.IsDigit(comment_v))
                        {
                            if (comment_c.Contains("-"))
                            {
                                commentsDic.Add("value", comment_v);
                                commentsDic.Add("name", comment_c.Substring(comment_c.IndexOf("-") + 1));
                                commentsDic.Add("comment", comment_c.Substring(0, comment_c.IndexOf("-")));
                            }
                        }
                        else
                        {
                            commentsDic.Add("value", comment_v);
                            commentsDic.Add("name", comment_v);
                            commentsDic.Add("comment", comment_c);
                        }
                        commentsDicL.Add(commentsDic);
                        if (commentsDic.Keys.Contains("value"))
                        {
                            resultL.Add("'" + commentsDic["value"] + "'");
                        }
                    }
                }
                result = resultL.ToArray();
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 表枚举类型列注释转换成可以处理的数组数据
        /// 注释风格如下:
        ///     用户性别
        ///     0:女-female
        ///     1:男-mail
        ///     -1:待确认-unknown
        ///     默认男
        /// </summary>
        /// <param name="Column_Comment">表枚举类型列注释</param>
        /// <returns></returns>
        protected List <Dictionary <string, string> > EnumDefines(string Column_Comment)
        {
            string C_Comment, Enum_Comment;

            string[] Part_Arr, Cn_En_Arr;
            List <Dictionary <string, string> > Result = null;

            string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (c_c.Length > 1)
            {
                Result = new List <Dictionary <string, string> >();
                for (int i = 1; i < c_c.Length; i++)
                {
                    C_Comment = c_c[i].Trim();
                    C_Comment = C_Comment.Replace(":", ":");
                    Part_Arr  = C_Comment.Split(':');
                    if ((Part_Arr != null) && (Part_Arr.Length == 2))
                    {
                        Cn_En_Arr    = new string[2];
                        Enum_Comment = Part_Arr[1];
                        if (UtilNumber.IsDigit(Part_Arr[0]))
                        {
                            if (Enum_Comment.Contains("-"))
                            {
                                Cn_En_Arr[0] = Enum_Comment.Substring(0, Enum_Comment.IndexOf("-"));
                                Cn_En_Arr[1] = Enum_Comment.Substring(Enum_Comment.IndexOf("-") + 1);
                                Result.Add(new Dictionary <string, string>()
                                {
                                    { "Name", Cn_En_Arr[1].ToLower() },
                                    { "Value", Part_Arr[0] },
                                    { "Comment", Cn_En_Arr[0] }
                                });
                            }
                        }
                        else
                        {
                            Result.Add(new Dictionary <string, string>()
                            {
                                { "Name", Part_Arr[0].ToLower() },
                                { "Value", Part_Arr[0].ToLower() },
                                { "Comment", Part_Arr[1] }
                            });
                        }
                    }
                }
            }
            return(Result);
        }