Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling DB Nulls
Message
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01440804
Message ID:
01440891
Vues:
31
>>>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?

string _ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString();

_ProjectName = _ProjectName.GetNonNull(); // would this work?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform