Beispiel #1
0
        public static object ChangeValueForType(Type type, string text)
        {
            string typename = type.ToString().Replace("System.Nullable`1[", "").Replace("]", "").Replace("System.", "").ToLower();

            switch (typename.ToLower())
            {
            case "decimal":
                return(ToolFunction.ToDec(text));

            case "int":
            case "int32":
            case "int64":
            case "long":
                return(ToolFunction.ToInt(text));

            case "double":
                return(ToolFunction.ToDouble(text));

            case "float":
                return(ToolFunction.ToFloat(text));

            case "string":
                return(text.ToString());

            case "bool":
            case "boolean":
                bool ret = false;
                if (text.ToString() == "是")
                {
                    ret = true;
                }
                if (text.ToString() == "1")
                {
                    ret = true;
                }
                if (text.ToString().ToLower() == "true")
                {
                    ret = true;
                }
                if (text.ToString() == "否")
                {
                    ret = false;
                }
                if (text.ToString() == "0")
                {
                    ret = false;
                }
                if (text.ToString().ToLower() == "false")
                {
                    ret = false;
                }
                return(ret);

            case "datetime":
                return(ToolFunction.ToDateTime(text));

            default:
                return(text);
            }
        }