I'd like to adapt this solution into an existing utility class of mine - just the GetProperty method. Thing is, my utility class is not generically-typed (i.e. the class declaration does not have a <T> parameter like PropertyHelper does), and I cannot add one for the time being.
In other words, I only want that GetProperty method to be generically-typed, not the whole class.
So what modifications do I need to make the method work? I've tried adding T to the list of generic types for that method:
public static PropertyInfo GetProperty<T, TValue>(Expression<Func<T, TValue>> selector)
But it gives me errors when I try doing the following:
PropertyInfo prop = MyUtilClass.GetProperty<Foo>(x => x.Bar);
Obviously, this is because GetProperty expects a T and a TValue...
I'd simply like to be able to call it like above. How?