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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -