开发者

Lambda expressions automated packing

public void aMethod<T>(Expression<Func<T, object>> lambda)
{
    ......
}

aMethod<User>(x=> x.UserId)

User is my custom class, members of his UserId int type...

I want the lambda expression x => x.UserId

But in the way,开发者_Go百科 I get is x => Convert (x.UserId) Therefore, the following operations can not, I need to ensure that my expression type Expression <Func <T, object>> it is not defined as Expression <Func <T, int>>

Is there any way it?


public void aMethod<T,TMember>(Expression<Func<T, TMember>> lambda)
{
    ......
}

aMethod<User>(x=> x.UserId)

object is a reference type. int a value type. if you get an int as an object, it must be packed :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜