示例#1
0
 public static Guid ToGuid(object data)
 {
     if (ValidationProvider.IsNullOrEmpty(data))
     {
         return(Guid.Empty);
     }
     try
     {
         return(new Guid(data.ToString()));
     }
     catch
     {
         return(Guid.Empty);
     }
 }
示例#2
0
 public static int ToInt32 <T>(T data)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(0);
         }
         return(Convert.ToInt32(data));
     }
     catch
     {
         return(0);
     }
 }
示例#3
0
 public static double ToDouble <T>(T data, int decimals, MidpointRounding pointRound)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(0.0);
         }
         return(Math.Round(Convert.ToDouble(data), decimals, pointRound));
     }
     catch
     {
         return(0.0);
     }
 }
示例#4
0
 public static float ToFloat <T>(T data)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(0f);
         }
         return(Convert.ToSingle(data));
     }
     catch
     {
         return(0f);
     }
 }
示例#5
0
 public static double ToDouble <T>(T data)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(0.0);
         }
         return(Convert.ToDouble(data));
     }
     catch
     {
         return(0.0);
     }
 }
示例#6
0
 public static double ToDouble(object data, int decimals)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <object>(data))
         {
             return(0.0);
         }
         return(Math.Round(Convert.ToDouble(data), decimals));
     }
     catch
     {
         return(0.0);
     }
 }
示例#7
0
 public static decimal ToDecimal <T>(T data, int decimals)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(0M);
         }
         return(Math.Round(Convert.ToDecimal(data), decimals));
     }
     catch
     {
         return(0M);
     }
 }
示例#8
0
 public static decimal ToDecimal(object data)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty(data))
         {
             return(0M);
         }
         return(Convert.ToDecimal(data));
     }
     catch
     {
         return(0M);
     }
 }
示例#9
0
 public static DateTime ToDateTime(object date)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty(date))
         {
             return(Convert.ToDateTime("1900-1-1"));
         }
         return(Convert.ToDateTime(date));
     }
     catch
     {
         return(Convert.ToDateTime("1900-1-1"));
     }
 }
示例#10
0
 public static bool ToBoolean <T>(T data)
 {
     try
     {
         if (ValidationProvider.IsNullOrEmpty <T>(data))
         {
             return(false);
         }
         return(Convert.ToBoolean(data));
     }
     catch
     {
         return(false);
     }
 }
示例#11
0
 public static object ConvertTo(object data, Type targetType)
 {
     if (ValidationProvider.IsNullOrEmpty(data))
     {
         return(null);
     }
     try
     {
         if (data is IConvertible)
         {
             return(Convert.ChangeType(data, targetType));
         }
         return(data);
     }
     catch
     {
         return(null);
     }
 }