private static Expression <Func <TModel, bool> > ToDateTimeOffsetValueExpression <TModel>(FilterItemModel filterItem, bool isNullable) where TModel : class { var nullableFilterValue = DateTimeOffsetHelper.ToDateTimeOffsetOrNull(filterItem.Value); if (!nullableFilterValue.HasValue || DateTimeOffsetHelper.DateTimeOffsetIsNullOrEmpty(nullableFilterValue)) { throw new ArgumentException($"{filterItem.Value} is not of type {typeof(DateTimeOffset)}."); } var filterValue = nullableFilterValue.Value; if (isNullable) { var entityParamSelector = ReflectionHelper.MemberSelector <TModel, DateTimeOffset?>(filterItem.Column); if (filterItem.Filter == FilterType.In) { var result = filterItem.CollectionExpression(entityParamSelector, DateTimeOffsetHelper.ToDateTimeOffsetOrNull); if (result != null) { return(result); } } var expression = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue); return(entityParamSelector.CombineSelectorParamExpression(expression)); } else { var entityParamSelector = ReflectionHelper.MemberSelector <TModel, DateTimeOffset>(filterItem.Column); if (filterItem.Filter == FilterType.In) { var result = filterItem.CollectionExpression(entityParamSelector, DateTimeOffsetHelper.ToDateTimeOffset); if (result != null) { return(result); } } var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue); return(entityParamSelector.CombineSelectorParamExpression(expression)); } }
public void DateTimeOffsetIsNullOrEmptyTest(object value, bool expected) { var actual = DateTimeOffsetHelper.DateTimeOffsetIsNullOrEmpty(value); Assert.Equal(expected, actual); }