I have a sample Data
class
public class Data
{
public int TestInt { get; set; }
public bool TestBool { get; set; }
public string TestString { get; set; }
public Data() { TestInt = 10; TestBool = true; TestString = "test"; }
}
And an extension method
public static void Method<T>(this T item, params Expression<Func<T, object>>[] properties)
{
/* Some stuff */
}
That I use like this
Data data = new Data();
data.Method(x => x.TestInt, x => x.TestBool, x => x.TestString);
My Method<T>
does receive 3 properties, but it has been slightly changed to:
properties[0] = x => Convert(x.TestId);
properties[1] = x => Convert(x.TestBool);
properties[2] = x => x.TestString;
As you can see, the TestString
part is unchanged. I tried changing my properties to params Expression<Func<T, bool>>[]
and params Expression<Func<T, int>>[]
and only pass the corresponding parameter and it works fine. I understand the problem comes from converting into an object
but I can't figure it out.