This is my generic Container class:
public class Container<T> : IContainer<T> where T : BaseModel, new()
{
private string include;
public Container()
{
}
public Container<T> Include(Expression<Func<T>> property)
{
include = GetMemberName(property);
return this;
}
}
Now I want to set the include value like this:
var container = new Container<TestClass>();
// doesn't work
container.Include(x => x.SomeProperty);
// also doesn't work
container.Include(() => TestClass.SomeProperty);
And as result the include
should habe the value SomeValue
. I also tried a parameterless Function, in the latter case VS says it's missing an object reference for the non-static property.
I got the GetMemberName from this thread: [Retrieving Property name from lambda expression