From: Donald L M. Jr. <lu...@us...> - 2004-12-07 21:33:00
|
Update of /cvsroot/nhibernate/NHibernateContrib/src/Nullables In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14167/src/Nullables Modified Files: NullableByte.cs NullableDateTime.cs NullableDecimal.cs NullableDouble.cs NullableGuid.cs NullableInt16.cs NullableInt32.cs NullableInt64.cs NullableSingle.cs Log Message: Added a simple implementation of IFormattable to the NullableTypes whos inner type supports it (it just wraps it). (Boolean doesn't implement IFormattable, the rest do) Index: NullableInt16.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableInt16.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt16.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableInt16.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt16Converter)), Serializable()] ! public struct NullableInt16 : INullableType { public static readonly NullableInt16 Default = new NullableInt16(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt16Converter)), Serializable()] ! public struct NullableInt16 : INullableType, IFormattable { public static readonly NullableInt16 Default = new NullableInt16(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableGuid.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableGuid.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableGuid.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableGuid.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 5,9 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableGuidConverter)), Serializable()] ! public struct NullableGuid : INullableType { public static readonly NullableGuid Default = new NullableGuid(); --- 5,9 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableGuidConverter)), Serializable()] ! public struct NullableGuid : INullableType, IFormattable { public static readonly NullableGuid Default = new NullableGuid(); *************** *** 123,126 **** --- 123,138 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableByte.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableByte.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableByte.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableByte.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableByteConverter)), Serializable()] ! public struct NullableByte : INullableType { public static readonly NullableByte Default = new NullableByte(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableByteConverter)), Serializable()] ! public struct NullableByte : INullableType, IFormattable { public static readonly NullableByte Default = new NullableByte(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableDecimal.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableDecimal.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDecimal.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableDecimal.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDecimalConverter)), Serializable()] ! public struct NullableDecimal : INullableType { public static readonly NullableDecimal Default = new NullableDecimal(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDecimalConverter)), Serializable()] ! public struct NullableDecimal : INullableType, IFormattable { public static readonly NullableDecimal Default = new NullableDecimal(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableSingle.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableSingle.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableSingle.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableSingle.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableSingleConverter)), Serializable()] ! public struct NullableSingle : INullableType { public static readonly NullableSingle Default = new NullableSingle(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableSingleConverter)), Serializable()] ! public struct NullableSingle : INullableType, IFormattable { public static readonly NullableSingle Default = new NullableSingle(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableDouble.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableDouble.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDouble.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableDouble.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDoubleConverter)), Serializable()] ! public struct NullableDouble : INullableType { public static readonly NullableDouble Default = new NullableDouble(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDoubleConverter)), Serializable()] ! public struct NullableDouble : INullableType, IFormattable { public static readonly NullableDouble Default = new NullableDouble(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableInt32.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableInt32.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt32.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableInt32.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 5,9 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt32Converter)), Serializable()] ! public struct NullableInt32 : INullableType { public static readonly NullableInt32 Default = new NullableInt32(); --- 5,9 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt32Converter)), Serializable()] ! public struct NullableInt32 : INullableType, IFormattable { public static readonly NullableInt32 Default = new NullableInt32(); *************** *** 155,158 **** --- 155,170 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableInt64.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableInt64.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt64.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableInt64.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt64Converter)), Serializable()] ! public struct NullableInt64 : INullableType { public static readonly NullableInt64 Default = new NullableInt64(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableInt64Converter)), Serializable()] ! public struct NullableInt64 : INullableType, IFormattable { public static readonly NullableInt64 Default = new NullableInt64(); *************** *** 154,157 **** --- 154,169 ---- return 0; //GetHashCode() doesn't garantee uniqueness, and neither do we. } + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } Index: NullableDateTime.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables/NullableDateTime.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDateTime.cs 12 Nov 2004 22:08:25 -0000 1.1 --- NullableDateTime.cs 7 Dec 2004 21:32:49 -0000 1.2 *************** *** 4,8 **** { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDateTimeConverter)), Serializable()] ! public struct NullableDateTime : INullableType { public static readonly NullableDateTime Default = new NullableDateTime(); --- 4,8 ---- { [System.ComponentModel.TypeConverter(typeof(Nullables.TypeConverters.NullableDateTimeConverter)), Serializable()] ! public struct NullableDateTime : INullableType, IFormattable { public static readonly NullableDateTime Default = new NullableDateTime(); *************** *** 124,127 **** --- 124,139 ---- //TODO: Operators for DateTime (?) + + #region IFormattable Members + + string System.IFormattable.ToString(string format, IFormatProvider formatProvider) + { + if (HasValue) + return Value.ToString(format, formatProvider); + else + return string.Empty; + } + + #endregion } } |