小编Pit*_*ing的帖子

如何在数组中获取方法参数?

想象一下,你在这个课程中得到了这个方法:

float Do(int a_,string b_){}
Run Code Online (Sandbox Code Playgroud)

我正在尝试做这样的事情:

float Do(int a_, string b_)
{
  var params = GetParamsListOfCurrentMethod(); //params is an array that contains (a_ and b_)
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

我为什么要这样做?

想象一下,你有一个接口:

public Interface ITrucMuch
{
 float Do(int a_,string b_);
 // And much more fct
}
Run Code Online (Sandbox Code Playgroud)

还有很多实现该接口的类

还有一个特殊的类,它也实现了接口:

public class MasterTrucMuch : ITrucMuch
{
  public floatDo(int a_, string b_) 
  {
    ITrucMuch tm = Factory.GetOptimizedTrucMuch(); // This'll return an optimized trucMuch based on some state
    if(tm != null)
    {
      return tm.Do(a_,b_);
    }
    else
    { …
Run Code Online (Sandbox Code Playgroud)

c#

6
推荐指数
2
解决办法
9028
查看次数

如何创建一个包含Any()调用的System.Linq.Expressions.Expression对象

我想动态生成一个linq.expressions.expression语句,我可以将其用作过滤器.

这是一个示例Linq查询,我想将其转换为Expression:

ctx.customer.where(c=>ctx.Invoice.Any(i=>i.customerId == c.id));
Run Code Online (Sandbox Code Playgroud)

这是我的尝试

using System.Linq.Expressions;
var c = Expression.parameter(typeof(Customer),"c");
var i = Expression.parameter(typeof(Invoice),"i");

var rightPart= Expression.Equal(
 Expression.propertyorField(i,"customerId"), Expression.propertyorfield(c,"id")
Run Code Online (Sandbox Code Playgroud)

请协助.

c# linq lambda linq-expressions

4
推荐指数
2
解决办法
9084
查看次数

标签 统计

c# ×2

lambda ×1

linq ×1

linq-expressions ×1