【发布时间】:2013-12-31 10:25:29
【问题描述】:
我有这样的静态方法:
public static string MyMethod(Func<Student, object> func)
{
return ??? ;
}
我使用它如下:
var s1 = MyMethod(student => student.ID); // Return "ID" ???
var s2 = MyMethod(student => student.Age); // Return "Age" ???
var s3 = MyMethod(student => student.Name); // Return "Name" ???
如何编写返回以下结果的方法?
- s1:“ID”
- s2:“年龄”
- s3:“名称”
* 将 => 之后的每个属性的名称作为字符串返回
【问题讨论】:
-
你不能使用这个签名——它必须是
Expression<Func<Student, object>>之类的东西。