Ejemplo n.º 1
0
        public override void Set(IDbCommand cmd, object value, int index)
        {
            IDataParameter parameter     = (IDataParameter)cmd.Parameters[index];
            NullableInt32  nullableValue = (NullableInt32)value;

            if (nullableValue.HasValue)
            {
                parameter.Value = nullableValue.Value;
            }
            else
            {
                parameter.Value = DBNull.Value;
            }
        }
        public override void Set(DbCommand cmd, object value, int index, ISessionImplementor session)
        {
            var           parameter     = cmd.Parameters[index];
            NullableInt32 nullableValue = (NullableInt32)value;

            if (nullableValue.HasValue)
            {
                parameter.Value = nullableValue.Value;
            }
            else
            {
                parameter.Value = DBNull.Value;
            }
        }
Ejemplo n.º 3
0
 public static bool Equals(NullableInt32 x, NullableInt32 y)
 {
     if (x.HasValue != y.HasValue)             //one is null
     {
         return(false);
     }
     else if (x.HasValue)             //therefor y also HasValue
     {
         return(x.Value == y.Value);
     }
     else             //both are null
     {
         return(true);
     }
 }
Ejemplo n.º 4
0
        public int CompareTo(object obj)
        {
            if (obj is NullableInt32)             //chack and unbox
            {
                NullableInt32 value = (NullableInt32)obj;

                if (value.HasValue == this.HasValue)       //both null or not null
                {
                    if (this.HasValue)                     //this has a value, so they both do
                    {
                        return(Value.CompareTo(value.Value));
                    }
                    else
                    {
                        return(0);                        //both null, so they are equal;
                    }
                }
                else                 //one is null
                {
                    if (HasValue)    //he have a value, so we are greater.
                    {
                        return(1);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            else if (obj is DateTime)
            {
                Int32 value = (Int32)obj;

                if (HasValue)                 //not null, so compare the real values.
                {
                    return(Value.CompareTo(value));
                }
                else
                {
                    return(-1);                    //this is null, so less that the real value;
                }
            }

            throw new ArgumentException("NullableInt32 can only compare to another NullableInt32 or a System.Int32");
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
                                         System.Type destinationType)
        {
            if (destinationType == typeof(InstanceDescriptor) && value is NullableInt32)
            {
                NullableInt32 nullable = (NullableInt32)value;

                System.Type[] constructorArgTypes = new System.Type[1] {
                    typeof(Int32)
                };
                ConstructorInfo constructor = typeof(NullableInt32).GetConstructor(constructorArgTypes);

                if (constructor != null)
                {
                    object[] constructorArgValues = new object[1] {
                        nullable.Value
                    };
                    return(new InstanceDescriptor(constructor, constructorArgValues));
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Ejemplo n.º 6
0
 public override object FromStringValue(string xml)
 {
     return(NullableInt32.Parse(xml));
 }
		public static bool Equals(NullableInt32 x, NullableInt32 y)
		{
			if (x.HasValue != y.HasValue) //one is null
				return false;
			else if (x.HasValue) //therefor y also HasValue
				return x.Value == y.Value;
			else //both are null
				return true;
		}
		public bool Equals(NullableInt32 x)
		{
			return Equals(this, x);
		}
Ejemplo n.º 9
0
 public bool Equals(NullableInt32 x)
 {
     return(Equals(this, x));
 }