private static string GetStringForExpression(ITranslator translator, Expression expression, Parameters parameters) { var memberExpression = expression as MemberExpression; if (memberExpression != null) { var constantExpression = memberExpression.Expression as ConstantExpression; if (constantExpression != null) { var container = constantExpression.Value; var member = memberExpression.Member; var fieldInfo = member as FieldInfo; if (fieldInfo != null) { var value = fieldInfo.GetValue(container); return(GetStringForExpression(translator, Expression.Constant(value), parameters)); } var propertyInfo = member as PropertyInfo; if (propertyInfo != null) { var value = propertyInfo.GetValue(container, null); return(GetStringForExpression(translator, Expression.Constant(value), parameters)); } } var tableDefinition = new TableDefinition(memberExpression.Member.DeclaringType); return(string.Concat(tableDefinition.Name, ".", memberExpression.Member.Name)); } var constExpr = expression as ConstantExpression; if (constExpr != null) { var value = GetValueFrom(translator, constExpr.Type, constExpr.Value); var key = parameters.Add(translator, value); return(key); } var methodExpression = expression as MethodCallExpression; if (methodExpression != null) { string concat; if (GetSqlExtensionMethodCallConstant(translator, methodExpression, parameters, out concat)) { return(concat); } } var newArrayExpression = expression as NewArrayExpression; if (newArrayExpression != null) { return(string.Join(",", newArrayExpression.Expressions.Select(ex => GetStringForExpression(translator, ex, parameters)))); } return(string.Empty); }
public static string ConstantExpressionString(ITranslator translator, ConstantExpression constantExpression, Parameters parameters) { var value = GetValueFrom(translator, constantExpression.Type, constantExpression.Value); return(parameters.Add(translator, value)); }