命名参数使用参数 [英] Named parameters with params
本文介绍了命名参数使用参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从数据库中获取值的方法
I have a method for getting values from database.
public virtual List<TEntity> GetValues(
int? parameter1 = null,
int? parameter2 = null,
int? parameter3 = null,
params Expression<Func<TEntity, object>>[] include)
{
//...
}
如何我可以调用与命名参数此功能可以不写在所有的参数包括:
?
我想要做这样的事情。
How can I call this function with named parameter to not write all parameters before include
?
I want to do something like this
var userInfo1 = Unit.UserSrvc.GetValues(include: p => p.Membership, p => p.User);
但这似乎不工作?的如何使用使用参数命名参数的
推荐答案
我认为唯一的办法是一样的东西?
I think the only way is something like:
GetValues(include:
new Expression<Func<TEntity, object>>[] { p => p.Membership, p => p.User })
这是不是很大。这将是可能是最好的,如果你添加了对过载:
Which is not that great. It would be probably best if you added an overload for that:
public List<Entity> GetValues(params Expression<Func<Entity, object>>[] include)
{
return GetValues(null, null, null, include);
}
然后调用你的方法,就像
Then you call your method just like
GetValues(p => p.Membership, p => p.User)
这篇关于命名参数使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文