0

I need to do the method below working

ExposeProperty((a) => a.Name); //not work

Error: Member 'Account2.Name' cannot be accessed with an instance reference; qualify it with a type name instead

public class Account2
{
    public static string Name
    {
        get { return "Foo"; }
    }
}

public class CustomReport<TEntity>
{
    public static void ExposeProperty<TProp>(Expression<Func<TEntity, TProp>> property)
    {
        //...
    }
    public static void ExposeProperty<TProp>(Expression<Func<TProp>> property)
    {
        //...
    }
}

public class AccountCustomReport2 : CustomReport<Account2>
{
    public static void Main()
    {
        ExposeProperty((a) => a.Name); //not work
        ExposeProperty(() => Account2.Name); //work
    }
}
Thomas Hilbert
  • 3,559
  • 2
  • 13
  • 33
William L
  • 31
  • 6
  • 1
    Use `Account2.Name` – Tim Schmelter May 05 '17 at 11:35
  • Please explain your use case. What you want to do makes no sense. – CodeCaster May 05 '17 at 11:36
  • @TimSchmelter, I don't think it's a duplicate because ExposeProperty for non-static member has different signature. William L did't explain the problem properly. Code would not work even if property was non-static.. – Andrii Litvinov May 05 '17 at 11:40
  • While the question is closed I cannot answer, but I suppose you need a way to invoke `ExposeProperty` for non-static property. You should provide a type: either `ExposeProperty((Account2 a) => a.Name2);` or `ExposeProperty((a) => a.Name2);` assuming there is a non-static Name2 property. – Andrii Litvinov May 05 '17 at 11:43

0 Answers0