lundi 21 septembre 2015

property names as params with compile check

I'm writing an utility class, that take a class name and array of property names as params like this:

public static IEnumerable<FieldInfo> GetPropertiesByNames([NotNull] Type parentType, params string[] include)

and call it looks like this:

Helper.GetPropertiesByNames(typeof(MonitoringDto), "ClientId", "PointId", "SerialNumber")

But i don like it, becouse there is no compile-check, and if i make mistake in string params, it will only runtime error, not compile error.

I want to do something lie this:

Helper.GetPropertiesByNames<MonitoringDto>(x => x.ClientId, x => x.PointId, x => x.SerialNumber)

Or, may be, even shorter. Is there any way to do this?





Aucun commentaire:

Enregistrer un commentaire