Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将MethodCallExpression附加到属性/参数_C#_.net_Lambda_Linq Expressions - Fatal编程技术网

C# 将MethodCallExpression附加到属性/参数

C# 将MethodCallExpression附加到属性/参数,c#,.net,lambda,linq-expressions,C#,.net,Lambda,Linq Expressions,我有以下MethodCallExpression: {Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))} 我需要将其附加到父级属性/参数,以便最终lambda如下所示: {txliferequest => txliferequest.OLifE.Party.Any(party => party.Address.Any(address => ad

我有以下MethodCallExpression:

{Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
我需要将其附加到父级属性/参数,以便最终lambda如下所示:

{txliferequest => txliferequest.OLifE.Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
最初的MethodCallExpression被传递到一个扩展方法中,因此我试图附加最终的lambda结构


TXLifeRequest

public partial class TXLifeRequest : BaseEntity
{
    public virtual OLifE OLifE { get; set; }

    ...
}
public partial class OLifE : BaseEntity
{
    public virtual List<Party> Party { get; set; }
        ...
}
public class Party: BaseEntity
{
    public virtual List<Address> Address { get; set; }
    ...
}

OLifE

public partial class TXLifeRequest : BaseEntity
{
    public virtual OLifE OLifE { get; set; }

    ...
}
public partial class OLifE : BaseEntity
{
    public virtual List<Party> Party { get; set; }
        ...
}
public class Party: BaseEntity
{
    public virtual List<Address> Address { get; set; }
    ...
}
公共部分类OLifE:BaseEntity
{
公共虚拟列表参与方{get;set;}
...
}

聚会

public partial class TXLifeRequest : BaseEntity
{
    public virtual OLifE OLifE { get; set; }

    ...
}
public partial class OLifE : BaseEntity
{
    public virtual List<Party> Party { get; set; }
        ...
}
public class Party: BaseEntity
{
    public virtual List<Address> Address { get; set; }
    ...
}
公共类参与方:基本实体
{
公共虚拟列表地址{get;set;}
...
}
我试图将is作为属性访问器附加,但不确定如何执行此操作。以下是我正在尝试的:

//{Name = "OLifE" FullName = "IMSParamed.Entities.OLifE"}
Type parentBaseType = parentPropInfo.GetListBaseType();

//{IMSParamed.Entities.OLifE OLifE}
PropertyInfo propInfo = parentBaseType.GetParentMappedPropertyInfo();

//{OLifE}
ParameterExpression parentTypeParam2 = parentPropInfo.Name.ToParameter(parentBaseType);

//{OLifE.Party}
MemberExpression typeProp = type.Name.ToProperty(parentTypeParam2);

//Type lambdaType = typeof(Func<,>).MakeGenericType(type, typeof(bool));

MethodInfo anyMethod = ExpressionBuilder.anyTSource.MakeGenericMethod(type);

//{OLifE.Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
MethodCallExpression any = Expression.Call(anyMethod, typeProp, methodCallExp);
/{Name=“OLifE”FullName=“IMSParamed.Entities.OLifE”}
类型parentBaseType=parentPropInfo.GetListBaseType();
//{IMSParamed.Entities.OLifE-OLifE}
PropertyInfo-propInfo=parentBaseType.GetParentMappedPropertyInfo();
//{OLifE}
ParameterExpression parentTypeParam2=parentPropInfo.Name.TopParameter(parentBaseType);
//{OLifE.Party}
MemberExpression typeProp=type.Name.TopProperty(parentTypeParam2);
//Type lambdaType=typeof(Func).MakeGenericType(Type,typeof(bool));
MethodInfo anyMethod=ExpressionBuilder.anyTSource.MakeGenericMethod(类型);
//{OLifE.Party.Any(Party=>Party.Address.Any(Address=>Address.Line1.Contains(“Address 1”))}
MethodCallExpression any=Expression.Call(anyMethod、typeProp、methodCallExp);

出现了什么错误?我猜我必须用正确的参数链重新构造MethodCallExpression。