Browse Source

update

master
wanggang 1 year ago
parent
commit
17cb888dd9
  1. 15
      code/src/Shared/Win.Sfs.Shared/Filter/FilterExtensions.cs

15
code/src/Shared/Win.Sfs.Shared/Filter/FilterExtensions.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Text.Json; using System.Text.Json;
@ -77,6 +78,7 @@ namespace Win.Sfs.Shared.Filter
//var constant = Expression.Constant(filterCondition.Value);//创建常数 //var constant = Expression.Constant(filterCondition.Value);//创建常数
ConstantExpression constant = null; ConstantExpression constant = null;
if (filterCondition.Action != EnumFilterAction.In && filterCondition.Action != EnumFilterAction.NotIn) if (filterCondition.Action != EnumFilterAction.In && filterCondition.Action != EnumFilterAction.NotIn)
{ {
constant = CreateConstantExpression(member.Type, filterCondition.Value); constant = CreateConstantExpression(member.Type, filterCondition.Value);
@ -150,12 +152,13 @@ namespace Win.Sfs.Shared.Filter
if (propertyType.IsGenericType && if (propertyType.IsGenericType &&
propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{ {
var objValue = Convert.ChangeType(value, propertyType.GetGenericArguments()[0]); var type = propertyType.GetGenericArguments()[0];
constant = Expression.Constant(objValue); var objValue = type.IsEnum ? (Enum)Enum.Parse(type, value, true) : Convert.ChangeType(value, type);
constant = Expression.Constant(new NullableConverter(propertyType).ConvertFrom(objValue));
} }
else if (propertyType.IsEnum) else if (propertyType.IsEnum)
{ {
var enumValue = (Enum)Enum.Parse(propertyType, value, true); var enumValue = (Enum?)Enum.Parse(propertyType, value, true);
constant = Expression.Constant(enumValue); constant = Expression.Constant(enumValue);
} }
else else
@ -174,7 +177,11 @@ namespace Win.Sfs.Shared.Filter
return constant; return constant;
} }
public static T? CreateNullable<T>(this T item) where T : struct
{
T? v = (T?)(new NullableConverter(typeof(T?))).ConvertFrom(item);
return v;
}
private static Expression<Func<T, bool>> GetExpressionLikeMethod<T>(string methodName, private static Expression<Func<T, bool>> GetExpressionLikeMethod<T>(string methodName,
FilterCondition filterCondition) FilterCondition filterCondition)
{ {

Loading…
Cancel
Save