Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Handling DB Nulls
Message
From
28/12/2009 14:21:56
 
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01440804
Message ID:
01440915
Views:
23
>>>>Kevin,
>>>>
>>>>I'm sure I've posted my GetNonNull set of static methods here a gazillion times. <g> Here it is again in the form of a link to my blog post about it:
>>>>
>>>>http://geek-goddess-bonnie.blogspot.com/2009/11/getting-non-null-data.html
>>>>
>>>>~~Bonnie
>>>>
>>>
>>>Bonnie,
>>>
>>>Is it fair to say that all types - except string - will be value types ?
>>>
>>>If so - consider this for the next update of the blog
>>>
>>>
>>>	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();
>>>		}
>>>	}
>>>
>>>
>>
>>
>>Ok, I created a static class called ExtensionMethods in my MiscFunctions solution. I referenced it in this project and added the using statement. When I type this:
>>
>>
>>_ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString();
>>
>>
>>I don't see GetNonNull in intellisense.
>>
>>What am I doing wrong?
>
>Are you confusing the static methods that Bonnie wrote with Extension methods ?


Both are static ...
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform