Given the following class:
class TestClass { public void SetValue(int value) { Value = value; } public int Value { get; set; } }
I can do
TestClass tc = new TestClass(); Action<int> setAction = tc.SetValue; setAction.Invoke(12);
which is all good. Is it possible to do the same thing using the property instead of the method? Preferably with something built in to .net.
You could create the delegate using reflection :
or create a delegate to an anonymous method which sets the property;
Edit: used wrong overload for CreateDelegate(), need to use the one that takes and object as target. Fixed.