I have the following simple switch statement. As you can see, the expressions for Any are almost identical.
My question is:
- Is there any way to re-use the expression so that I don't have to repeat it every time I need the same or similar expression.
- if not possible to re-use the whole expression in Any, is it possible to re-use "x => x.Question == _question.Question" at least?
Thanks!
switch (_question.DataField)
{
case DataField.FormData:
result = Report.ReportDataItems.Any(
x => x.Question == _question.Question
&& (!string.IsNullOrEmpty(x.FormData)) && Int32.TryParse(x.FormData, out tempVal));
break;
case DataField.FormData2:
result = Report.ReportDataItems.Any(
x => x.Question == _question.Question
&& (!string.IsNullOrEmpty(x.FormData2)) && Int32.TryParse(x.FormData2, out tempVal));
break;
}