Beispiel #1
0
        public virtual object Cast(Type type, object obj)
        {
            object result;

            if (type.IsArray)
            {
                result = obj;
            }
            else if (type.IsEnum)
            {
                result = InnerConvert.ToInt32(obj);
            }
            else if (type.Equals(typeof(short)) || type.Equals(typeof(byte)) || type.Equals(typeof(byte)) || type.Equals(typeof(short)))
            {
                result = InnerConvert.ToInt16(obj);
            }
            else if (type.Equals(typeof(long)) || type.Equals(typeof(long)))
            {
                result = InnerConvert.ToInt64(obj);
            }
            else if (type.Equals(typeof(int)) || type.Equals(typeof(int)))
            {
                result = InnerConvert.ToInt32(obj);
            }
            else if (type.Equals(typeof(double)) || type.Equals(typeof(float)) || type.Equals(typeof(double)))
            {
                result = InnerConvert.ToDouble(obj);
            }
            else if (type.Equals(typeof(decimal)))
            {
                result = InnerConvert.ToDecimal(obj);
            }
            else
            {
                if (type.Equals(typeof(bool)))
                {
                    obj = InnerConvert.ToBoolean(obj);
                }
                else if (type.Equals(typeof(DateTime)))
                {
                    obj = InnerConvert.ToDateTime(obj);
                }
                else if (obj != null && !type.Equals(typeof(byte[])) && obj.GetType().Equals(typeof(byte[])))
                {
                    IFormatter   formatter    = new BinaryFormatter();
                    MemoryStream memoryStream = new MemoryStream(obj as byte[]);
                    obj = formatter.Deserialize(memoryStream);
                    memoryStream.Close();
                }
                result = obj;
            }
            return(result);
        }
Beispiel #2
0
 public static short ToInt16(object obj)
 {
     return(InnerConvert.ToInt16(obj, 0));
 }
Beispiel #3
0
 public static long ToInt64(object obj)
 {
     return(InnerConvert.ToInt64(obj, 0L));
 }
Beispiel #4
0
 public static int ToInt32(object obj)
 {
     return(InnerConvert.ToInt32(obj, 0));
 }
Beispiel #5
0
 public static double ToDouble(object obj)
 {
     return(InnerConvert.ToDouble(obj, 0.0));
 }
Beispiel #6
0
 public static DateTime ToDateTime(object obj)
 {
     return(InnerConvert.ToDateTime(obj, DateTime.Now));
 }
Beispiel #7
0
 public static string ToString(object obj)
 {
     return(InnerConvert.ToString(obj, ""));
 }