Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7649659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:01:26+00:00 2026-05-31T11:01:26+00:00

What do you people think about this solution to encapsulate a collection and be

  • 0
  1. What do you people think about this solution to encapsulate a collection and be able to know when an iten is added/removed.

  2. How can I add a clicable link to the xml description?

    // Why does DoNotExposeGenericLists recommend that I expose Collection instead of List? by David Kean"
    // http://blogs.msdn.com/b/codeanalysis/archive/2006/04/27/585476.aspx
    public class CollectionEx<T> : Collection<T>
    {
    public event EventHandler ItemAdded;
    public event EventHandler ItemRemoved;
    
    public CollectionEx()//:base()
    {
    }
    
    protected override void InsertItem(int index, T item)
    {
        base.InsertItem(index, item);
        OnSectionAdded(EventArgs.Empty);
    }
    
    protected override void RemoveItem(int index)
    {
        base.RemoveItem(index);
        OnSectionRemoved(EventArgs.Empty);
    }
    
    public new void Add(T item)
    {
        base.Add(item);
        OnSectionAdded(EventArgs.Empty);
    }
    public new bool Remove(T item)
    {
        bool ok = base.Remove(item);
        OnSectionRemoved(EventArgs.Empty);
        return ok;
    }
    
    protected override void ClearItems()
    {
        base.ClearItems();
    }
    
    protected virtual void OnSectionRemoved(EventArgs e)
    {
        EventHandler handler = this.ItemRemoved;
        if (handler != null)
        {
            handler(this, e);
        }
    }
    
    protected virtual void OnSectionAdded(EventArgs e)
    {
        EventHandler handler = this.ItemAdded;
        if (handler != null)
        {
            handler(this, e);
        }
    }
    

    }

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:01:27+00:00Added an answer on May 31, 2026 at 11:01 am

    You can use ObservableCollection<T> for this purpose. No need to write it yourself.

    Besides: When subclassing Collection<T> it’s enough to override the protected virtual methods. All other public methods will invoke them.
    If you additionally hide the non-virtual ones the way you did, events might be triggered multiple times (and in your case, when clearing the collection, no event will be triggered).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like know what people think about using RAISERROR in stored procedures to pass
I think most people know how to do this via the GUI (right click
As I think most people know already, or if you don't, FPDF released a
I have seen a lot of people with this error and no solution seems
Just wondering what people think is the best practice when implementing an IValueConverter which
I'm curious How do you people think ? (I mean a way of thinking)
Based on a few posts I've read concerning version control, it seems people think
Where I work, people mostly think that objects are best initialised using C++-style construction
I think most people here understand the importance of fully automated builds. The problem
I think there are a lot of people out there unaware of RFC's (Request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.