none
Property Change RRS feed

  • Question

  • I'm currently trying to create business objects for a series of projects I am working on.  I am creating a base business object for all business objects to derive from.  My question is, is there an event/delegate that I could use that notifies me of a property changing on a derived object? I would like to make the derived object as easy to use as possible for other developers. Ideally, I would like them to code their objects like this:

    public class Derived : BusinessObjBase
    {
          private string m_name;
          private in m_id;

          public string Name
          {
                get{ return m_name; }
                set { m_name = value; }
          }

          public int Id
          {
                get{ return m_id; }
                set { m_id = value; }
          }
          ...
    }

    and still be notified that a property changed, as opposed to them having to remember to explicitly call a notify delegate in every set like this:

    public class Derived : BusinessObjBase
    {
          private string m_name;
          private in m_id;

          public string Name
          {
                get{ return m_name; }
                set {
                            NotifyChanged("Name", new MyPropertyChangedEvt(m_name, value));
                            m_name = value;
                      }
          }

          public int Id
          {
                get{ return m_id; }
                set {
                            NotifyChanged("Id", new MyPropertyChangedEvt(m_id, value));
                            m_id = value;
                      }
          }
          ...
    }

    Is this possible or do I need to force them to call a Notify delegate?
    Thursday, September 17, 2009 3:37 AM

Answers

  • I have not found a way to do this. So I will keep an eye on this thread to see if someone else has a better answer for you.

    However, I did build a code snippet and provided  it  to all of the members of the team. The snippet built the property statement including the property changed. That way it was relatively easy to ensure it got put in there.

    Hope this helps.

    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Marked as answer by ZJohnson Thursday, September 17, 2009 8:10 PM
    Thursday, September 17, 2009 3:49 AM