tags:

views:

54

answers:

2
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, 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?

A: 
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 :-)

cRichter
How to write? In the method body in
Dreampuf
its hard, if you write just partially english sentences.... so, do you want to know what should be in the body of the method? then please explain what it should do...
cRichter
= =!...Because I have a lot of code is based on aMethod <T> (xxxx) to write, if we want to change the technology will cost a lot of time. So there is no other way?
Dreampuf
As the second parameter is explicitly an object, i do not think there is a chance. but when you change the method, and recomplile the project i do not think you need to change anything. as they are compatible then (but you need to recompile)
cRichter
As you can see, because my code has many layers, which in fact is the data access layer, which led to a little change in the code above, I almost have to go. So can people talk about other methods?
Dreampuf