I use relection to make a dynamic filter. But when I've a DateTime field, I want to exclude from my search date=Nothing.
Dim Expr As Expression = Expression.Property(paramExpr, pinfo)
Dim Typ = pinfo.PropertyType.FullName
Dim CondPart As Expression = Nothing
Dim toStr As Expression = Nothing
If Typ.Contains("DateTime") Then
toStr = Expression.Call(Expr, "ToString", Nothing, Expression.Constant("yyyyMMdd")) 'Here string to exclude "00010101" -> 01/01/0001
Else
toStr = Expression.Call(If(pinfo.PropertyType.IsValueType, Expr, Expression.Coalesce(Expr, Expression.Constant(String.Empty))), "ToString", Nothing)
End If
Dim indexOf As Expression = Expression.Call(toStr, "IndexOf", Nothing, Expression.Constant(MesDonnees.FiltreGeneral), Expression.Constant(StringComparison.OrdinalIgnoreCase))
CondPart = Expression.NotEqual(indexOf, Expression.Constant(-1))
If conditionGbl Is Nothing Then
conditionGbl = CondPart
Else
conditionGbl = Expression.OrElse(conditionGbl, CondPart)
End If
I try to put
toStr = Expression.Call(Expr, "ToString", Nothing, Expression.Constant("yyyyMMdd"))
toStr = Expression.NotEqual(toStr, Expression.Constant("00010101"))
But I've error
No method 'IndexOf' exists on the type 'System.Boolean'
I Think it's between NotEqual and indexOf.
I try too
Dim NoNullDte As Expression = Expression.Call(Expr, "ToString", Nothing, Expression.Constant("yyyyMMdd"))
toStr = Expression.Call(NoNullDte, "IndexOf", Nothing, Expression.Constant("00010101"), Expression.Constant(StringComparison.OrdinalIgnoreCase))
But there, I've error:
No method 'IndexOf' exists on the type 'System.Int32'
Someone know How I can exclude the null date, properly?
Aucun commentaire:
Enregistrer un commentaire