Checking NULL in C# LINQ expression -


i have linq expression converts dateformat utc date format of user culture.

for (int = 0; < datexml.count ; i++) {     if (datatype.tolower() == "date")     {           mylist.select(c => { ((object[])(c))[i] =    convertfromutcdate( convert.todatetime (((object[])(c))[i]),  usertimezone); return c; }).tolist();     } } 

some times date value in (object[])(c))[i] null or have string or decimal if value wrongly stored in db.

how check if values not null , has date , convert in expression.

to avoid adding more complexity , being able read , maintain code easily, extract anonymous method , make named method

from

c => { ((object[])(c))[i] = convertfromutcdate( convert.todatetime (((object[])(c))[i]), usertimezone); return c; }

to

public datetime convertfromobjecttodate(object dbdate){     if(dbdate null || !(dbdate datetime))return datetime.minvalue;      var result =   convertfromutcdate(convert.todatetime (dbdate),usertimezone);       return result;  } 

and

c => {((object[])(c))[i] =  convertfromobjecttodate(((object[])(c))[i]);} 

Comments

Popular posts from this blog

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World