internal static T GetValueFromEqualsExpression <T>(BinaryExpression be, Type memberDeclaringType, string memberName) { if (!ValuableNodeTypes.HasFlag(be.NodeType)) { throw new Exception("There is a bug in this program."); } if (be.Left.NodeType == ExpressionType.MemberAccess) { MemberExpression me = (MemberExpression)be.Left; if (me.Member.DeclaringType == memberDeclaringType && me.Member.Name == memberName) { return(GetValueFromExpression <T>(be.Right)); } } else if (be.Right.NodeType == ExpressionType.MemberAccess) { MemberExpression me = (MemberExpression)be.Right; if (me.Member.DeclaringType == memberDeclaringType && me.Member.Name == memberName) { return(GetValueFromExpression <T>(be.Left)); } } else if (be.Right.NodeType == ExpressionType.Constant) { var ce = (ConstantExpression)be.Right; return((T)ce.Value); } // We should have returned by now. //throw new Exception("There is a bug in this program."); return(default(T)); }
public static bool Matches(ExpressionType expressionType, Type type) { if (type == typeof(int) || type == typeof(double) || type == typeof(decimal)) { return(expressionType.HasFlag(ExpressionType.number)); } if (type == typeof(string)) { return(expressionType.HasFlag(ExpressionType.text)); } if (type == typeof(bool)) { return(expressionType.HasFlag(ExpressionType.boolean)); } if (type.IsEnum) { return(expressionType.HasFlag(ExpressionType.@enum)); } return(false); }