IsNullOrEmpty extension method


hi everybody,

i wondering if idea of introducing isnullorempty method object , if is, perhaps implemented , can post not re-invent wheel. thinking should return true 0 if numeric type, same result isnullorempty string, datetime should check default date , null , boolean check false , null. rest of types check null.

thanks in advance.


for every expert, there equal , opposite expert. - becker's law


my blog


i tend avoid adding methods - @ least extension methods, tend cause type less discoverable looking @ code.  if see "isnullorempty" method, assume it's working on string, that's thing has it.

that being said, isn't needed.  if you're working nullable types, null-coalescing operator (??) does you:

bool? value = getnullablebool();  // can use in if statements: // true if value has value , true if (value ?? false)  { }   // if need "default" value: datetime date = getnullabledatevalue() ?? datetime.now; double dbl = getdoubleval() ?? 0.0;


reed copsey, jr. - http://reedcopsey.com
if post answers question, please click "mark answer" on post , "mark helpful".



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'