I was wondering if anyone had some thoughts on assigning a Delegate to a Property, as defining a "Property Delegate" does not seem to be allowed in VB.NET. However, since the underlying accessor methods are really just get_Property() and set_Property(value) methods, this restriction seems odd.
In VB.NET, the accessor methods do not appear to be publicly exposed. Are they in C#? (I'm guessing no?)
I guess I could create a Public Get and Set method pair and have those methods called by the respective Property Get and Property Set functions. But since the methods would have to be public (if I wish to assign delegates to them) it is then redundant to also have a public property doing exactly the same thing -- so I may as well throw out the property altogether and just stick with a Get and Set method pair only.
I could use an interface that includes a property and then pass in a reference to the class that implements the property. This is fine, I guess, but not as flexible as a delegate, unless one is willing to make a lot of pre-defined interfaces with different property return types.
A final thought is that I could use Reflection to find the property's accessor methods and then create an instance of the PropertyInfo class, which would effectively become my *Delegate*. A little ugly, but doable.
Funny that I could create a "surrogate delegate" via a PropertyInfo class or via a class+interface, but directly using a Delegate class appears to be off limits to Properties...
Does anyone have any thoughts or ideas on this?
Mike
In VB.NET, the accessor methods do not appear to be publicly exposed. Are they in C#? (I'm guessing no?)
I guess I could create a Public Get and Set method pair and have those methods called by the respective Property Get and Property Set functions. But since the methods would have to be public (if I wish to assign delegates to them) it is then redundant to also have a public property doing exactly the same thing -- so I may as well throw out the property altogether and just stick with a Get and Set method pair only.
I could use an interface that includes a property and then pass in a reference to the class that implements the property. This is fine, I guess, but not as flexible as a delegate, unless one is willing to make a lot of pre-defined interfaces with different property return types.
A final thought is that I could use Reflection to find the property's accessor methods and then create an instance of the PropertyInfo class, which would effectively become my *Delegate*. A little ugly, but doable.
Funny that I could create a "surrogate delegate" via a PropertyInfo class or via a class+interface, but directly using a Delegate class appears to be off limits to Properties...
Does anyone have any thoughts or ideas on this?
Mike
Last edited: