Exemple #1
0
        public static object GetValue(FieldInfo field, string stringValue)
        {
            string type = field.FieldType.Name;

            if (ParseUtility.IsInt64(type))
            {
                return(long.Parse(stringValue));
            }
            if (ParseUtility.IsInt32(type))
            {
                return(int.Parse(stringValue));
            }
            if (ParseUtility.IsSingle(type))
            {
                return(float.Parse(stringValue));
            }
            if (ParseUtility.IsDouble(type))
            {
                return(double.Parse(stringValue));
            }
            if (ParseUtility.IsBoolean(type))
            {
                return(bool.Parse(stringValue));
            }
            return(stringValue);
        }
Exemple #2
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name;

                if (ParseUtility.IsInt64(type))
                {
                    para = new LongPara(field);
                }
                if (ParseUtility.IsInt32(type))
                {
                    para = new IntPara(field);
                }
                if (ParseUtility.IsSingle(type))
                {
                    para = new FloatPara(field);
                }
                if (ParseUtility.IsDouble(type))
                {
                    para = new DoublePara(field);
                }
                if (ParseUtility.IsString(type))
                {
                    para = new StringPara(field);
                }
                if (ParseUtility.IsBoolean(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }
Exemple #3
0
 public static bool ContainType(string type)
 {
     return(ParseUtility.IsBoolean(type) || ParseUtility.IsSingle(type) || ParseUtility.IsDouble(type) || ParseUtility.IsInt64(type) || ParseUtility.IsInt32(type) || ParseUtility.IsString(type));
 }