Ejemplo n.º 1
0
        //读取ini字符流中的某个属性的值
        public static string ReadIniStringKeyValue(string iniStrings, string key, char[] separator)
        {
            string result = null;

            string[] temp = MyStringHelper.SplitString(iniStrings, separator);

            if (temp != null && temp.Length > 0)
            {
                foreach (var item in temp)
                {
                    if (item.ToLower().Contains(key.ToLower()))
                    {
                        result = item.Substring(key.Length + 1);
                        //break;
                        return(result);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static string MakeIniStringExt(Object obj, string equalOperator = "=", string lastSplit = ";", bool removeLastlastSplit = true)
        {
            string        schema = string.Format("{0}{1}{2}{3}", "{0}", equalOperator, "{1}", lastSplit);
            StringBuilder sb     = new StringBuilder();

            if (obj != null)
            {
                //获取类型信息
                Type           t             = obj.GetType();
                PropertyInfo[] propertyInfos = t.GetProperties();
                foreach (PropertyInfo var in propertyInfos)
                {
                    object value = var.GetValue(obj, null);
                    string temp  = "";

                    //如果是string,并且为null
                    if (value == null)
                    {
                        temp = "";
                    }
                    else
                    {
                        temp = value.ToString();
                    }

                    value = MyStringHelper.ReplaceString(temp, new[] { lastSplit, "=" });
                    sb.AppendFormat(schema, var.Name, value);
                }
            }
            //去掉最后的分号
            if (removeLastlastSplit)
            {
                string result = sb.ToString();
                return(result.Substring(0, result.Length - 1));
            }
            else
            {
                return(sb.ToString());
            }
        }