Is it possible to wrap a property setter directly with a delegate?

I tried the following without success.  I don't want to have to code a separate method just so I can pass the setter function to another class as I'm going to be doing this a lot.



public class MyClass
{
   public delegate void SetStringDelegate( string value);

   public string MyProperty
   {
      get{ return myProperty; }
      set{ myProperty = value; }
   }

   public void DoTest()
   {
      /* This gives compile error "cannot explicitly call ... accessor" */
      SetStringDelegate SetString = new SetStringDelegate( set_MyProperty); 

      /* This gives compile error "Property ... used like ... Method" */
      SetStringDelegate SetString2 = new SetStringDelegate( MyProperty)
   }
}   

 



Answer this question

Is it possible to wrap a property setter directly with a delegate?