How Func<DomainObject,object> return Object name as string

Viewed 249

I have static method like this :

    public static string MyMethod(Func<Student, object> func)
    {            
        return ??? ;
    }

and I use it as following :

    var s1 = MyMethod(student => student.ID); // Return "ID" ???
    var s2 = MyMethod(student => student.Age); // Return "Age" ???
    var s3 = MyMethod(student => student.Name); // Return "Name" ???

How write method that return the following results ?

  • s1 : "ID"
  • s2 : "Age"
  • s3 : "Name"

* return each property`s name after => as string

3 Answers
Related