Example #1
0
 public static ulong ToUInit64(string str, ulong defaultValue)
 {
     return((ulong)ConverterHelper.ToObject(TypeCode.UInt64, str, defaultValue));
 }
Example #2
0
        public static bool Compare(CompareOp op, object val, string compareVal, Type type)
        {
            if (val == null)
            {
                if (string.IsNullOrEmpty(compareVal) || compareVal.Trim().ToLower() == "null" || compareVal.Trim().ToLower() == "nothing")
                {
                    switch (op)
                    {
                    case CompareOp.GreaterThan:
                    case CompareOp.LessThan:
                    case CompareOp.NotEqual: return(false);

                    default: return(true);
                    }
                }
                else
                {
                    switch (op)
                    {
                    case CompareOp.Equal:
                    case CompareOp.GreaterOrEqual:
                    case CompareOp.GreaterThan: return(false);

                    default: return(true);
                    }
                }
            }
            else if (type.IsGenericType && type.Name.IndexOf("Nullable") != -1)
            {
                Type underType = Nullable.GetUnderlyingType(type);
                if (underType == typeof(bool))
                {
                    return(CompareHelper.Compare <bool>(op,
                                                        ((bool?)val).Value,
                                                        ConverterHelper.ToBoolean(compareVal, false)));
                }
                else if (underType == typeof(long))
                {
                    return(CompareHelper.Compare <long>(op,
                                                        ((long?)val).Value,
                                                        ConverterHelper.ToInt64(compareVal, long.MinValue)));
                }
                else if (underType == typeof(int))
                {
                    return(CompareHelper.Compare <int>(op,
                                                       ((int?)val).Value,
                                                       ConverterHelper.ToInt32(compareVal, int.MinValue)));
                }
                else if (underType == typeof(short))
                {
                    return(CompareHelper.Compare <short>(op,
                                                         ((short?)val).Value,
                                                         ConverterHelper.ToInt16(compareVal, short.MinValue)));
                }
                else if (underType == typeof(ulong))
                {
                    return(CompareHelper.Compare <ulong>(op,
                                                         ((ulong?)val).Value,
                                                         ConverterHelper.ToUInit64(compareVal, ulong.MinValue)));
                }
                else if (underType == typeof(uint))
                {
                    return(CompareHelper.Compare <uint>(op,
                                                        ((uint?)val).Value,
                                                        ConverterHelper.ToUInit32(compareVal, uint.MinValue)));
                }
                else if (underType == typeof(ushort))
                {
                    return(CompareHelper.Compare <ushort>(op,
                                                          ((ushort?)val).Value,
                                                          ConverterHelper.ToUInt16(compareVal, ushort.MinValue)));
                }
                else if (underType == typeof(double))
                {
                    return(CompareHelper.Compare <double>(op,
                                                          ((double?)val).Value,
                                                          ConverterHelper.ToDouble(compareVal, double.MinValue)));
                }
                else if (underType == typeof(decimal))
                {
                    return(CompareHelper.Compare <decimal>(op,
                                                           ((decimal?)val).Value,
                                                           ConverterHelper.ToDecimal(compareVal, decimal.MinValue)));
                }
                else if (underType == typeof(Single))
                {
                    return(CompareHelper.Compare <Single>(op,
                                                          ((Single?)val).Value,
                                                          ConverterHelper.ToSingle(compareVal, Single.MinValue)));
                }
                else if (underType == typeof(DateTime))
                {
                    return(CompareHelper.Compare <DateTime>(op,
                                                            ((DateTime?)val).Value,
                                                            ConverterHelper.ToDateTime(compareVal, DateTime.MinValue)));
                }
                else if (underType == typeof(char))
                {
                    return(CompareHelper.Compare <char>(op,
                                                        ((char?)val).Value,
                                                        ConverterHelper.ToChar(compareVal, char.MinValue)));
                }
                else if (underType == typeof(byte))
                {
                    return(CompareHelper.Compare <byte>(op,
                                                        ((byte?)val).Value,
                                                        ConverterHelper.ToByte(compareVal, byte.MinValue)));
                }
                else if (underType == typeof(sbyte))
                {
                    return(CompareHelper.Compare <sbyte>(op,
                                                         ((sbyte?)val).Value,
                                                         ConverterHelper.ToSByte(compareVal, sbyte.MinValue)));
                }
            }
            else if (type == typeof(string) || type.IsValueType)
            {
                if (string.IsNullOrEmpty(compareVal) || compareVal.Trim().ToLower() == "null" || compareVal.Trim().ToLower() == "nothing")
                {
                    switch (op)
                    {
                    case CompareOp.GreaterThan:
                    case CompareOp.GreaterOrEqual:
                    case CompareOp.NotEqual: return(true);

                    default: return(false);
                    }
                }
                else
                {
                    IComparable tmpCompareVal = ConverterHelper.ToObject(type, compareVal, null) as IComparable;
                    IComparable tmpVal        = (IComparable)val;

                    return(CompareHelper.Compare(op, tmpVal, tmpCompareVal));
                }
            }

            return(false);
        }
Example #3
0
 public static ushort ToUInt16(string str, ushort defaultValue)
 {
     return((ushort)ConverterHelper.ToObject(TypeCode.UInt16, str, defaultValue));
 }
Example #4
0
 public static uint ToUInit32(string str, uint defaultValue)
 {
     return((uint)ConverterHelper.ToObject(TypeCode.UInt32, str, defaultValue));
 }
Example #5
0
 public static sbyte ToSByte(string str, sbyte defaultValue)
 {
     return((sbyte)ConverterHelper.ToObject(TypeCode.SByte, str, defaultValue));
 }
Example #6
0
 public static Single ToSingle(string str, Single defaultValue)
 {
     return((Single)ConverterHelper.ToObject(TypeCode.Single, str, defaultValue));
 }
Example #7
0
 public static int ToInt32(string str, int defaultValue)
 {
     return((int)ConverterHelper.ToObject(TypeCode.Int32, str, defaultValue));
 }
Example #8
0
 public static long ToInt64(string str, long defaultValue)
 {
     return((long)ConverterHelper.ToObject(TypeCode.Int64, str, defaultValue));
 }
Example #9
0
 public static double ToDouble(string str, double defaultValue)
 {
     return((double)ConverterHelper.ToObject(TypeCode.Double, str, defaultValue));
 }
Example #10
0
 public static decimal ToDecimal(string str, decimal defaultValue)
 {
     return((decimal)ConverterHelper.ToObject(TypeCode.Decimal, str, defaultValue));
 }
Example #11
0
 public static DateTime ToDateTime(string str, DateTime defaultValue)
 {
     return((DateTime)ConverterHelper.ToObject(TypeCode.DateTime, str, defaultValue));
 }
Example #12
0
 public static char ToChar(string str, char defaultValue)
 {
     return((char)ConverterHelper.ToObject(TypeCode.Char, str, defaultValue));
 }
Example #13
0
 public static bool ToBoolean(string str, bool defaultValue)
 {
     return((bool)ConverterHelper.ToObject(TypeCode.Boolean, str, defaultValue));
 }