Consider an interface like this:
new Provider().For(myClass).ExcludeProperties("Height", "Width");
public IEditableStateProvider For(object target) {...}
public IEditableStateProvider ExcludePropertyNames(params string[] propertyNames) {...}
I want to replace the params string[] propertyNames
arg with params Expression<Func<object>>[] propertyNames
so that I would instead have the following.
new Provider().For(myClass).ExcludeProperties(()=>Height, ()=>Width);
I have seen code similar to this so I think it should work, but I am not getting it yet. How can I get this to work?
EDIT - doing this without Generics
Here is some code from an open source project I was looking at where type inference is working without any generics. I was looking to do the same but I don't see where the type inference is coming from (I do see it working though!)
// USAGE (here this is being called from code-behind of a WPF window
private void TrackSelectedTab() {
Services.Tracker.Configure(tabControl)
.AddProperties(() => tabControl.SelectedIndex);
Services.Tracker.ApplyState(tabControl);
}
private void TrackMainWindow() {
Services.Tracker.Configure(this)
.AddProperties(
() => Height,
() => Width,
() => Left,
() => Top,
() => WindowState)
.SetKey("MainWindow")
.SetMode(PersistModes.Automatic);
Services.Tracker.ApplyState(this);
}
// Collab classes
public class SettingsTracker
{
public TrackingConfiguration Configure(object target) {
...
return config;
}
}
public class TrackingConfiguration
{
public TrackingConfiguration AddProperties(params Expression<Func<object>>[] properties) {
...
return this;
}
}
static class Services
{
public static readonly SettingsTracker Tracker = new SettingsTracker(ObjectStore);
}