小编Pat*_*ick的帖子

具有格式/文化的表达式树ToString

所以这是我想要实现的基础:

string.Format(new CultureInfo("da-DK"), "{0:n}", myDouble)
Run Code Online (Sandbox Code Playgroud)

(用文化格式化数字.示例输入:1,输出:"1,00")

上下文:我需要使用表达式树实现这一点,我当前的代码生成一个搜索查询,通过产品价格,它应该格式化双精度.这是我到目前为止所得到的:

 var query = context.Products;
 var searchquery = "1,00" //example
 var propertyName = "Price"; //example
 var parameterExp = Expression.Parameter(typeof(ProductClass), "type");
 var propertyExp = Expression.Property(parameterExp, propertyName);
 MethodCallExpression propertyExpToStringToLower; //value initialized depending on type.
 if (propertyExp.Type == typeof(double))
 {
 // Example value: 1, needed value: "1,00".                                              
 // Here I want to change the double to the correct format, ToString.
 }
 else
 {
 //ToString's and ToLower's other attributes (string, int, where no format is needed)
 propertyExpToStringToLower = …
Run Code Online (Sandbox Code Playgroud)

c# linq expression expression-trees

2
推荐指数
1
解决办法
157
查看次数

标签 统计

c# ×1

expression ×1

expression-trees ×1

linq ×1