Know when inherited collection is modified?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sstory

    Know when inherited collection is modified?

    I have a class in vb.net that
    Inherits Generic.List(Of myclass)

    I want to have totals in this class that are static...i.e. not recalculated
    every time. They should be calculated once and never again unless the
    collection is modified, or the data in one of the objects in the collection
    is changed. How can I do this?

    Thanks,

    Shane


  • Lloyd Sheen

    #2
    Re: Know when inherited collection is modified?

    sstory wrote:
    I have a class in vb.net that
    Inherits Generic.List(Of myclass)
    >
    I want to have totals in this class that are static...i.e. not recalculated
    every time. They should be calculated once and never again unless the
    collection is modified, or the data in one of the objects in the collection
    is changed. How can I do this?
    >
    Thanks,
    >
    Shane
    >
    >
    I think that one part of your question can be dealt with easily
    (somewhat). Since you inherit the list you can override the methods
    that modify the collection like Add/AddRange/Clear etc. You would have
    to do this since there are no events thrown when the collection is modified.

    When that happens you can recalc the totals.

    To know when members within the collection are modified you would have
    to have those items raise and event when a value you want to watch is
    changed.

    LS

    Comment

    • sstory

      #3
      Re: Know when inherited collection is modified?

      OK. I am shadowing each method as overrides is not allowed. You are correct
      this should solve problem1.

      As far as events goes, I can't imagine how I could make an event in MyClass
      that would fire in the containing collection.
      How could that happen?

      Thanks,

      Shane
      "Lloyd Sheen" <a@b.cwrote in message
      news:eb6DP1x9IH A.448@TK2MSFTNG P04.phx.gbl...
      sstory wrote:
      >I have a class in vb.net that
      >Inherits Generic.List(Of myclass)
      >>
      >I want to have totals in this class that are static...i.e. not
      >recalculated every time. They should be calculated once and never again
      >unless the collection is modified, or the data in one of the objects in
      >the collection is changed. How can I do this?
      >>
      >Thanks,
      >>
      >Shane
      I think that one part of your question can be dealt with easily
      (somewhat). Since you inherit the list you can override the methods that
      modify the collection like Add/AddRange/Clear etc. You would have to do
      this since there are no events thrown when the collection is modified.
      >
      When that happens you can recalc the totals.
      >
      To know when members within the collection are modified you would have to
      have those items raise and event when a value you want to watch is
      changed.
      >
      LS

      Comment

      • Lloyd Sheen

        #4
        Re: Know when inherited collection is modified?

        sstory wrote:
        OK. I am shadowing each method as overrides is not allowed. You are correct
        this should solve problem1.
        >
        As far as events goes, I can't imagine how I could make an event in MyClass
        that would fire in the containing collection.
        How could that happen?
        >
        Thanks,
        >
        Shane
        "Lloyd Sheen" <a@b.cwrote in message
        news:eb6DP1x9IH A.448@TK2MSFTNG P04.phx.gbl...
        >sstory wrote:
        >>I have a class in vb.net that
        >>Inherits Generic.List(Of myclass)
        >>>
        >>I want to have totals in this class that are static...i.e. not
        >>recalculate d every time. They should be calculated once and never again
        >>unless the collection is modified, or the data in one of the objects in
        >>the collection is changed. How can I do this?
        >>>
        >>Thanks,
        >>>
        >>Shane
        >I think that one part of your question can be dealt with easily
        >(somewhat). Since you inherit the list you can override the methods that
        >modify the collection like Add/AddRange/Clear etc. You would have to do
        >this since there are no events thrown when the collection is modified.
        >>
        >When that happens you can recalc the totals.
        >>
        >To know when members within the collection are modified you would have to
        >have those items raise and event when a value you want to watch is
        >changed.
        >>
        >LS
        >
        >
        Since you are now shadowing each collection modifier, you can now get a
        list of the object being added. Create an interface which is just an
        event. The event parameters should either give you information on what
        was changed but since you already have a calc routine you most likely
        only need to know about the change.

        Then for each object added do an addhandler to an event handler which
        will cause the calc routine to be called.

        LS

        Comment

        • sstory

          #5
          Re: Know when inherited collection is modified?

          Very elegant solution! I never thought of that. I think it will work fine.

          Thanks!


          "Lloyd Sheen" <a@b.cwrote in message
          news:u7DSfOy9IH A.2496@TK2MSFTN GP04.phx.gbl...
          sstory wrote:
          >OK. I am shadowing each method as overrides is not allowed. You are
          >correct this should solve problem1.
          >>
          >As far as events goes, I can't imagine how I could make an event in
          >MyClass that would fire in the containing collection.
          >How could that happen?
          >>
          >Thanks,
          >>
          >Shane
          >"Lloyd Sheen" <a@b.cwrote in message
          >news:eb6DP1x9I HA.448@TK2MSFTN GP04.phx.gbl...
          >>sstory wrote:
          >>>I have a class in vb.net that
          >>>Inherits Generic.List(Of myclass)
          >>>>
          >>>I want to have totals in this class that are static...i.e. not
          >>>recalculat ed every time. They should be calculated once and never
          >>>again unless the collection is modified, or the data in one of the
          >>>objects in the collection is changed. How can I do this?
          >>>>
          >>>Thanks,
          >>>>
          >>>Shane
          >>I think that one part of your question can be dealt with easily
          >>(somewhat). Since you inherit the list you can override the methods
          >>that modify the collection like Add/AddRange/Clear etc. You would have
          >>to do this since there are no events thrown when the collection is
          >>modified.
          >>>
          >>When that happens you can recalc the totals.
          >>>
          >>To know when members within the collection are modified you would have
          >>to have those items raise and event when a value you want to watch is
          >>changed.
          >>>
          >>LS
          >>
          >>
          >
          Since you are now shadowing each collection modifier, you can now get a
          list of the object being added. Create an interface which is just an
          event. The event parameters should either give you information on what
          was changed but since you already have a calc routine you most likely only
          need to know about the change.
          >
          Then for each object added do an addhandler to an event handler which will
          cause the calc routine to be called.
          >
          LS

          Comment

          • sstory

            #6
            Re: Know when inherited collection is modified?

            Thanks! it worked great!
            "Lloyd Sheen" <a@b.cwrote in message
            news:u7DSfOy9IH A.2496@TK2MSFTN GP04.phx.gbl...
            sstory wrote:
            >OK. I am shadowing each method as overrides is not allowed. You are
            >correct this should solve problem1.
            >>
            >As far as events goes, I can't imagine how I could make an event in
            >MyClass that would fire in the containing collection.
            >How could that happen?
            >>
            >Thanks,
            >>
            >Shane
            >"Lloyd Sheen" <a@b.cwrote in message
            >news:eb6DP1x9I HA.448@TK2MSFTN GP04.phx.gbl...
            >>sstory wrote:
            >>>I have a class in vb.net that
            >>>Inherits Generic.List(Of myclass)
            >>>>
            >>>I want to have totals in this class that are static...i.e. not
            >>>recalculat ed every time. They should be calculated once and never
            >>>again unless the collection is modified, or the data in one of the
            >>>objects in the collection is changed. How can I do this?
            >>>>
            >>>Thanks,
            >>>>
            >>>Shane
            >>I think that one part of your question can be dealt with easily
            >>(somewhat). Since you inherit the list you can override the methods
            >>that modify the collection like Add/AddRange/Clear etc. You would have
            >>to do this since there are no events thrown when the collection is
            >>modified.
            >>>
            >>When that happens you can recalc the totals.
            >>>
            >>To know when members within the collection are modified you would have
            >>to have those items raise and event when a value you want to watch is
            >>changed.
            >>>
            >>LS
            >>
            >>
            >
            Since you are now shadowing each collection modifier, you can now get a
            list of the object being added. Create an interface which is just an
            event. The event parameters should either give you information on what
            was changed but since you already have a calc routine you most likely only
            need to know about the change.
            >
            Then for each object added do an addhandler to an event handler which will
            cause the calc routine to be called.
            >
            LS

            Comment

            Working...