Yes, infoof would be a great feature.
But, in C# 3.0 expression trees can do the trick.
But, in C# 3.0 expression trees can do the trick.
Code Block
using System;
using System.Reflection;
using System.Linq.Expressions;
class Person
{
public int Age { get; set; }
}
class Program
{
static void Main()
{
var person = new Person();
var age = InfoOf(() => person.Age);
Console.WriteLine(age.Name);
}
static PropertyInfo InfoOf<T>(Expression<Func<T>> ex)
{
return (PropertyInfo)((MemberExpression)ex.Body).Member;
}
}