How to check if a property of type String is null so that my next code works and does not interrupt during a method call?
if (SelectedOperator is StringOperators)
{
MethodInfo method;
var value = Expression.Constant(Value);
switch ((StringOperators)SelectedOperator)
{
case StringOperators.Is:
condition = Expression.Equal(property, value);
break;
case StringOperators.IsNot:
condition = Expression.NotEqual(property, value);
break;
case StringOperators.StartsWith:
method = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
condition = Expression.Call(property, method, value);
break;
case StringOperators.Contains:
method = typeof(string).GetMethod("Contains", new[] { typeof(string) });
condition = Expression.Call(property, method, value);
break;
case StringOperators.EndsWith:
method = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
condition = Expression.Call(property, method, value);
break;
}
}
source
share