public static class BBExtensions { public static DateTime GetNonNull(this object Test, DateTime Default) { if (Test != null && Test != DBNull.Value) { DateTime TestDT = Convert.ToDateTime(Test); DateTime SqlNull = new DateTime(1900, 1, 1); DateTime NetNull = new DateTime(1, 1, 1); if (TestDT != SqlNull && TestDT != NetNull) return TestDT; else return Default; } else return Default; } public static int GetNonNull(this object Test, int Default) { if (Test != null && Test != DBNull.Value) return Convert.ToInt32(Test); else return Default; } }~~Bonnie
> public static class ExtensionMethods > { > //______________________________________________________________________ > public static T GetNonNull<T>(this T? value) where T : struct > { > return value == null ? default(T) : (T)value; > } > //______________________________________________________________________ > public static string GetNonNull(this string value) > { > return value == null ? "" : value; > } > //______________________________________________________________________ > } > > >// test >public class test2 > { > > > //______________________________________________________________________ > public static void Main( string[] args ) > { > int? i = null; > bool? b = null; > string x = null; > DateTime? dt = null; > > Console.WriteLine("i: {0}", i.GetNonNull()); > Console.WriteLine("b: {0}", b.GetNonNull()); > Console.WriteLine("x: {0}", x.GetNonNull()); > Console.WriteLine("dt: {0}", dt.GetNonNull()); > > Console.ReadLine(); > } > } > >