473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Generic Collection Pattern

Without generics generally I'd dervie from CollectionBase to create typed
collections. Generics mostly fill in this gap except that there are no
virtual methods on List<T> so we can no longer notify other object when a
collection changes during add, remove and set operations. I was curious how
Others were getting around this problem? I thought of doing something like:

class MyCollection : IList<T>, ICollection<T>
{
private List<T> m_list;
}

Then simply operate on m_list for each of the implementation of the
interfaces. I feel like there's a simpler solution out there that I'm not
seeing.

Thanks
Jun 1 '06 #1
5 1973
"Brian Richards" <br*******@gmail.com> a écrit dans le message de news:
OW**************@TK2MSFTNGP05.phx.gbl...

| Without generics generally I'd dervie from CollectionBase to create typed
| collections. Generics mostly fill in this gap except that there are no
| virtual methods on List<T> so we can no longer notify other object when a
| collection changes during add, remove and set operations. I was curious
how
| Others were getting around this problem? I thought of doing something
like:

Take a look at BindingList<T>.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jun 1 '06 #2
Thanks! Looks like what I was looking for.

-Brian

"Joanna Carter [TeamB]" <jo****@not.for.spam> wrote in message
news:uz**************@TK2MSFTNGP04.phx.gbl...
"Brian Richards" <br*******@gmail.com> a écrit dans le message de news:
OW**************@TK2MSFTNGP05.phx.gbl...

| Without generics generally I'd dervie from CollectionBase to create typed | collections. Generics mostly fill in this gap except that there are no
| virtual methods on List<T> so we can no longer notify other object when a | collection changes during add, remove and set operations. I was curious
how
| Others were getting around this problem? I thought of doing something
like:

Take a look at BindingList<T>.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Jun 1 '06 #3

Brian Richards wrote:
Without generics generally I'd dervie from CollectionBase to create typed
collections. Generics mostly fill in this gap except that there are no
virtual methods on List<T> so we can no longer notify other object when a
collection changes during add, remove and set operations. I was curious how
Others were getting around this problem?


I asked a similar question here: <http://tinyurl.com/lntcp>

--
Larry Lard
Replies to group please

Jun 1 '06 #4
Just hide the base class's method with the new operator. Example (from a
class the inherits System.Collections.Generic.Dictionary):

new virtual public void Add(string key, T value)
{
base.Add(key, value);
// add an event here if you wish.
}

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Abnormality is anything but average.

"Brian Richards" <br*******@gmail.com> wrote in message
news:OW**************@TK2MSFTNGP05.phx.gbl...
Without generics generally I'd dervie from CollectionBase to create typed
collections. Generics mostly fill in this gap except that there are no
virtual methods on List<T> so we can no longer notify other object when a
collection changes during add, remove and set operations. I was curious
how
Others were getting around this problem? I thought of doing something
like:

class MyCollection : IList<T>, ICollection<T>
{
private List<T> m_list;
}

Then simply operate on m_list for each of the implementation of the
interfaces. I feel like there's a simpler solution out there that I'm not
seeing.

Thanks

Jun 1 '06 #5
That's not such a hot idea if you intend passing the container around cast
as an interface or as an instance of the base class; if you can't override,
then you can /only/ change the behaviour when code knows the object /as/ the
new class. Personally I wouldn't advise this.

Marc
Jun 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: JAL | last post by:
Here is my first attempt at a deterministic collection using Generics, apologies for C#. I will try to convert to C++/cli. using System; using System.Collections.Generic; using System.Text; ...
8
by: Steven Cummings | last post by:
Hello, I've scoured this usenet group and didn't find anything specific to my problem, so hopefully this won't be a repeated question. I'm all but certain it's not. I would like to *declare*...
3
by: snesbit | last post by:
I have a structure called SearchAreaListItem. The structure has some properties. The application implements this as a collection.generic.list(of SearchAreaListItem) I load the collection up ...
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
4
by: =?Utf-8?B?QkogU2FmZGll?= | last post by:
We have a class that has a public property that is of type List<T>. FXCop generates a DoNotExposeGenericLists error, indicating "System.Collections.Generic.List<Tis a generic collection designed...
5
by: sloan | last post by:
I've noticed alot of people tacking on a "T" for a generic abled version of an older class. Ex: 1.1 Code IDataStore
2
by: jehugaleahsa | last post by:
Hello: I was reading another post and saw an argument (sort of) that brought up a good question. I have written a fairly large library of algorithms that occur in programming all the time. It...
9
by: tadmill | last post by:
Is it possible to pass a generic parameter of the same class to to its constructor, where the "T" type passed in the constructor is different than the "T" type of the instanced class? ie, ...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.