I’m trying to create a method signature that takes multiple properties of various type using
I would call it something like this:
AllPropertiesExcept(() => Property1, () => Property2)
This method almost work, except that the type of the properties have to be the same. I’m only going to use the property name, but want to use lambda expression to enable easy refactoring.
public static string MyMethod<T>(params Expression<Func<T>>[] propertyExpression)
I would use
AllPropertiesExcept(params Expression<Func<object>>[] properties), you can still get the property names out of it, but it doesn’t matter what type the property is.Edit: However, I would tend to use it the other way round – instead of excluding properties I don’t want to see, I would include properties I want to see. The reason is simple – to make your way work, you still need reflection – with my way, you could easily use the
Funcyou get to get the actual data directly.Edit 2 (getting the property name out of an expression):
I can really advise you to use LinqPad for such things, you can easily drill down objects via
Dump(), which displays the objects very user friendly. Just recreate a small example and experiment.