private Type GetNoOffsetPropertyType(BsColumnOrder orderColumn) { var propertyInfo = typeof(TRow).GetProperty(orderColumn.Name); var baseType = propertyInfo.PropertyType.BaseType; if (baseType.Name == (typeof(BsGridColumnValue).Name)) { var mockValue = new BsGridColumnValue <object, object>(); propertyInfo = propertyInfo.PropertyType.GetProperties().FirstOrDefault(p => p.Name == mockValue.GetPropertyName(x => x.ItemValue)); } var propertyType = propertyInfo.PropertyType; return(propertyType); }
private BsExpressionMembers GetExpressionMembers(Type propertyType, BsColumnOrder orderColumn, ParameterExpression pe) { Expression left, right; object value; var parameterSetVisitor = new ParameterReplaceVisitor(); var finalType = Nullable.GetUnderlyingType(propertyType) ?? propertyType; if (orderColumn.Value != null) { if (finalType == typeof(DateTime)) { long binaryDate; var succceded = Int64.TryParse(orderColumn.Value.ToString(), out binaryDate); if (succceded) { value = DateTime.FromBinary(binaryDate); } else { value = Convert.ChangeType(orderColumn.Value, finalType); } } else { value = propertyType.IsEnum ? Enum.Parse(propertyType, orderColumn.Value.ToString()) : Convert.ChangeType(orderColumn.Value, finalType); } } else { value = orderColumn.Value; } var criteria = this.orderedQueryBuilder.GetCriteria(orderColumn.Name); if (criteria != null) { var body = criteria.GetBody(); left = parameterSetVisitor.ReplaceParameter(body, pe); } else { left = Expression.Property(pe, orderColumn.Name); } right = Expression.Constant(value, propertyType); if (propertyType == typeof(string)) { var stringCompare = Expression.Call(left, typeof(string).GetMethod("CompareTo", new[] { typeof(string) }), right); var zeroConstant = Expression.Constant(0, typeof(int)); left = stringCompare; right = zeroConstant; } else if (propertyType.IsEnum) { left = Expression.Convert(left, typeof(long)); right = Expression.Convert(right, typeof(long)); } return(new BsExpressionMembers { Left = left, Right = right }); }