All:
I'd like to create a delegate for a property (as opposed to a method). Can
I do this? If so, please teach me the syntactic magic.
For example, suppose I have a boolean ready-only property defined in an
instance of a class name SomeObj as follows:
public bool TheValue
{
get
{
// do some work
return someBoolValue;
}
}
I've tried the following two approaches to creating the delegate but
received compilation errors:
private delegate bool BoolDelegate();
// The following results in compilation error: error CS0118: denotes a
'property' where a 'method' was expected
BoolDelegate del = new BoolDelegate(SomeObj.TheValue);
// The following results in compilation error: error CS0571: cannot
explicitly call operator or accessor
BoolDelegate del = new BoolDelegate(SomeObj.get_TheValue);
Any other ideas?
TIA,
Bill