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

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -