以字符串形式获取属性static的名称

时间:2017-05-05 11:33:55

标签: c#

我需要按照以下方法进行操作

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

错误:无法使用实例引用访问成员“Account2.Name”;使用类型名称来限定它

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
    }
}

0 个答案:

没有答案