First I'll describe what I'm trying to achieve.
I want to create a method that grabs a property name and its value for logging purposes, so I have this:
public void Log<TPropertySource, TProperty>(Expression<Func<TPropertySource, object>> property, TProperty initialValue, TProperty changedValue){...}
Now this requires me to specify the property's type, which is .. meh, because in theory I can pull that from an expression; however expression needs to return an object to accommodate for all the possible types the property can have.
I'm thinking about just having overloads for BCL's most used value types, and an overload with object for everything else, e.g.
public void Log<TPropertySource>(Expression<Func<TPropertySource, string>> property, string initialValue, string changedValue){...}
public void Log<TPropertySource>(Expression<Func<TPropertySource, int>> property, int initialValue, int changedValue){...}
but its not ideal either, because I'll end up with like a dozen overloads
So basically I wonder if there is a better (lazier) way to do it ?
One more question: why do I get no intellisense on Log<TPropertySource>(Expression<Func<TPropertySource, int>> property, int initialValue, int changedValue) ? If I type logger.Log<A>(x => x.Age, 1, 2); - it compiles fine, but intellisense just won't kick in.