473,396 Members | 1,866 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,396 software developers and data experts.

Custom Collection Confusion

Assume that you would like to create a custom collection class that is:

1. Strongly-typed (only holds Customer objects)
2. Read-only (user cannot add Customer objects)
3. Able to be bound to a winforms datagrid (must implement the IList
interface).

What would be a good way to create this class?

1. The CollectionBase abstract base class can be used, but it is not
read-only.
2. The ReadOnlyCollection abstract base class can be used, but it doesn't
implement IList and therefore can't be bound.
3. The IList interface includes an "IsReadOnly" property, so why does the
ReadOnlyCollection base class
not implement the IList interface, with IsReadOnly set to return "true"??
(Instead, it doesn't implement IList at all).
Nov 13 '05 #1
9 4810
> What would be a good way to create this class?

This seems be a very common question and I'm often confused by the varying
answers posted here.

I'm wondering if those with an opinion would be willing to post to a
WikisWeb for future reference?
Go here: http://dotnet.wikis.com/wc.dll?dotnet~CollectionClasses
And click "Edit" to modify the contents of the page to add your two cents.

Just an idea.
Nov 13 '05 #2
Craig,

I would ignore the last post. It's just spam for a C# site. The text
is so generic I could post it in a gardening newsgroup and get the same
thing. As an example, check out what I posted:

http://dotnet.wikis.com/wc.dll?DotNe...kYourSpamSucks

What I would do is create a class that extends ReadOnlyCollectionBase,
and implement IList yourself, throwing InvalidOperationExceptions on the
implementation of Add, Remove, etc, etc that would violate the read-only
status.

Then I would create the custom collection as normal, but not include
type-safe methods for Remove, Add, and the set indexer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"craig" <e@mail.com> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
What is a WikisWeb??

"MHelland" <mh******@techmocracy.net> wrote in message
news:Op**************@TK2MSFTNGP11.phx.gbl...
What would be a good way to create this class?


This seems be a very common question and I'm often confused by the varying answers posted here.

I'm wondering if those with an opinion would be willing to post to a
WikisWeb for future reference?
Go here: http://dotnet.wikis.com/wc.dll?dotnet~CollectionClasses
And click "Edit" to modify the contents of the page to add your two cents.
Just an idea.


Nov 13 '05 #3
What are you, a newsgroup Nazi? - I just came out here as a result of
reading your post. Now I am reminded why I hate newsgroups. I get a
headache trying to find anything of use out here. Wiki's are a much
better place to share knowledge. Mike's right, you don't know what
you're talking about.

Nicholas Paldino [.NET/C# MVP] wrote:
Craig,

I would ignore the last post. It's just spam for a C# site. The text
is so generic I could post it in a gardening newsgroup and get the same
thing. As an example, check out what I posted:

http://dotnet.wikis.com/wc.dll?DotNe...kYourSpamSucks

What I would do is create a class that extends ReadOnlyCollectionBase,
and implement IList yourself, throwing InvalidOperationExceptions on the
implementation of Add, Remove, etc, etc that would violate the read-only
status.

Then I would create the custom collection as normal, but not include
type-safe methods for Remove, Add, and the set indexer.

Hope this helps.


Nov 13 '05 #4
Mike,

I just received an email from Steven Black about this, and apparently, I
might have erred. However, I do have to say that your post had a few items
in it that led me to respond in that manner:

You wrote:
---
What would be a good way to create this class?


This seems be a very common question and I'm often confused by the varying
answers posted here.
---

Your post was initially the only response to the original poster's post
in this group. I took "here" to mean this group. Based on that, it would
seem that the responder did not really read the post, or it was automatic.
On top of that, a search on google.com for this group only turns up 16
results for ReadOnlyCollectionBase dating back to July of 2001.

In retrospect, I feel that I did act in haste, and I apologize for that.
As I stated in my email to Steven Black, I have no problem with people
promoting their sites that promote .NET and knowledge in general, but in my
initial analysis of the response, I felt that the promotion was coming under
the guise of helping the original poster, which it certainly did not.

My apologies to anyone that might have been offended. The reply was in
no way meant to criticize the content or the efficacy of the site, but
rather, the methods used to promote it. Looking back, I feel that I have
erred, and I apologize for that.

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike Helland" <mh******@techmocracy.net> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It's just spam for a C# site.


You don't know what you're talking about.

Nov 13 '05 #5
In light of this apology, I hope you'll accept my apology to you and I
would also like to retract my calling you a newsgroup Nazi. That was
uncalled for.

Nicholas Paldino [.NET/C# MVP] wrote:
Mike,

I just received an email from Steven Black about this, and apparently, I
might have erred. However, I do have to say that your post had a few items
in it that led me to respond in that manner:

You wrote:
---
What would be a good way to create this class?

This seems be a very common question and I'm often confused by the varying
answers posted here.
---

Your post was initially the only response to the original poster's post
in this group. I took "here" to mean this group. Based on that, it would
seem that the responder did not really read the post, or it was automatic.
On top of that, a search on google.com for this group only turns up 16
results for ReadOnlyCollectionBase dating back to July of 2001.

In retrospect, I feel that I did act in haste, and I apologize for that.
As I stated in my email to Steven Black, I have no problem with people
promoting their sites that promote .NET and knowledge in general, but in my
initial analysis of the response, I felt that the promotion was coming under
the guise of helping the original poster, which it certainly did not.

My apologies to anyone that might have been offended. The reply was in
no way meant to criticize the content or the efficacy of the site, but
rather, the methods used to promote it. Looking back, I feel that I have
erred, and I apologize for that.


Nov 13 '05 #6
> On top of that, a search on google.com for this group only turns up 16
results for ReadOnlyCollectionBase dating back to July of 2001.


Yes, well, I too probably posted my message to the wrong thread. A couple
days ago there was a thread called:

'Bad design of C# collections framework. Where is the "Set" collection?'

And similar ones have seemed to appear every couple of days. I was going to
post the wikis recommendation to Bad Design one, but decided against it.
When I saw the new collection thread today, I figured I might as well chuck
it out there, not seeing that the question was specifically about read only
collections.

I'd still like to see a central wikis topic on clr collections, if you have
anything to add, that'd be cool.
Nov 13 '05 #7
Randy,

Thank you, it is much appreciated, and apology accepted.

However, I don't know if I can forgive you for the following things:

- Criticism of the technology used on my personal site.
- Criticism of where I was brought up.

Just kidding =)

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Randy Jean" <no**********@ogse.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In light of this apology, I hope you'll accept my apology to you and I
would also like to retract my calling you a newsgroup Nazi. That was
uncalled for.

Nicholas Paldino [.NET/C# MVP] wrote:
Mike,

I just received an email from Steven Black about this, and apparently, I might have erred. However, I do have to say that your post had a few items in it that led me to respond in that manner:

You wrote:
---
What would be a good way to create this class?

This seems be a very common question and I'm often confused by the varying answers posted here.
---

Your post was initially the only response to the original poster's post in this group. I took "here" to mean this group. Based on that, it would seem that the responder did not really read the post, or it was automatic. On top of that, a search on google.com for this group only turns up 16
results for ReadOnlyCollectionBase dating back to July of 2001.

In retrospect, I feel that I did act in haste, and I apologize for that. As I stated in my email to Steven Black, I have no problem with people
promoting their sites that promote .NET and knowledge in general, but in my initial analysis of the response, I felt that the promotion was coming under the guise of helping the original poster, which it certainly did not.

My apologies to anyone that might have been offended. The reply was in no way meant to criticize the content or the efficacy of the site, but
rather, the methods used to promote it. Looking back, I feel that I have erred, and I apologize for that.

Nov 13 '05 #8
http://www.sellsbrothers.com/tools/

"CollectionGen is a Custom Tool Add-In to VS.NET 2002 & 2003 to
generate type-safe collections. As it turns out, I did almost none of
the work. Jon Flanders figured out how to add a custom tool. Shawn Van
Ness implemented the template for type-safe collections. I just put it
together.

CollectionGen is an add-on to generate code for type-safe collections
until we have templates in C# (likely) and VB (unlikely). The benefit
of a type-safe collection, of course, is that you can use it without
having to cast items to and from objects. Also, Shawn has been very
careful to implement a collection class that is very efficient for
both reference types and value types.

Once you've setup it up and defined your collections in a collection
definition file in your project, you'll have type-safe collection
classes generated as part of your design-process, as shown here:"
"craig" <e@mail.com> wrote in message news:<u8**************@TK2MSFTNGP11.phx.gbl>...
Assume that you would like to create a custom collection class that is:

1. Strongly-typed (only holds Customer objects)
2. Read-only (user cannot add Customer objects)
3. Able to be bound to a winforms datagrid (must implement the IList
interface).

What would be a good way to create this class?

1. The CollectionBase abstract base class can be used, but it is not
read-only.
2. The ReadOnlyCollection abstract base class can be used, but it doesn't
implement IList and therefore can't be bound.
3. The IList interface includes an "IsReadOnly" property, so why does the
ReadOnlyCollection base class
not implement the IList interface, with IsReadOnly set to return "true"??
(Instead, it doesn't implement IList at all).

Nov 13 '05 #9
Since CollectionBase implements IList, derive a class from
CollectionBase and implement IsReadOnly in that class.

"craig" <e@mail.com> wrote in message news:<u8**************@TK2MSFTNGP11.phx.gbl>...
Assume that you would like to create a custom collection class that is:

1. Strongly-typed (only holds Customer objects)
2. Read-only (user cannot add Customer objects)
3. Able to be bound to a winforms datagrid (must implement the IList
interface).

What would be a good way to create this class?

1. The CollectionBase abstract base class can be used, but it is not
read-only.
2. The ReadOnlyCollection abstract base class can be used, but it doesn't
implement IList and therefore can't be bound.
3. The IList interface includes an "IsReadOnly" property, so why does the
ReadOnlyCollection base class
not implement the IList interface, with IsReadOnly set to return "true"??
(Instead, it doesn't implement IList at all).

Nov 13 '05 #10

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

Similar topics

3
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the...
0
by: panik | last post by:
Hi, I have a custom collection that implements CollectionBase. The collection is called Sensors and contains a list of Sensor objects. There is the usual index using an integer (Sensors). ...
8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
1
by: Jeff S | last post by:
I'm storing a list of widgets in a database. The list changes infrequently (twice per week at most), and is relatively short (200 items at most, with very little detail per item). A small subset of...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
4
by: Stuart | last post by:
I hope someone can shed some light on an error I've been experiencing for sometime now, but can no longer continue to ignore :-( I've created a custom entity class which implements IEditableObject....
7
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.