Blog of Denis VOITURON

for a better .NET world

Collection snippet

Posted on 2012-02-19

Often, I need to create lists of data. It is obviously possible to use generic lists (List), but they are not easily expandable. For example, it is not possible to remove the Add and Remove methods, it is also difficult to add an event OnChanged that would detect when a property of object (T) change.

So, we must implement our collection that inherits from CollectionBase and IEnumerable</strong> to allow LINQ queries.

To simplify the creation of these collections, I’ve prepared a Snippet to include in Visual Studio (Tools / Code Snippets Manager / Import). You can easily use it (Ctrl+K, Ctrl+X) and choose the name of the class… all methods are automatically adapted.

  1. Select the ClassCollection snippet (Ctrl+K, Ctrl+X).

  1. Write you class name (Employee, Department, etc).

  1. And use it.

Remarks: The snippet diagram class is.

File: Download the snippet ClassCollection here.



Follow me

Recent posts