473,695 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ReadOnlyCollect ion 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
ReadOnlyCollect ion 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 4823
> 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 ReadOnlyCollect ionBase,
and implement IList yourself, throwing InvalidOperatio nExceptions 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************* *@exisconsultin g.com

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

"MHelland" <mh******@techm ocracy.net> wrote in message
news:Op******** ******@TK2MSFTN GP11.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 ReadOnlyCollect ionBase,
and implement IList yourself, throwing InvalidOperatio nExceptions 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 ReadOnlyCollect ionBase 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************* *@exisconsultin g.com

"Mike Helland" <mh******@techm ocracy.net> wrote in message
news:u9******** ******@TK2MSFTN GP12.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 ReadOnlyCollect ionBase 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 ReadOnlyCollect ionBase 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************* *@exisconsultin g.com

"Randy Jean" <no**********@o gse.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.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 ReadOnlyCollect ionBase 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/

"Collection Gen 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******* *******@TK2MSFT NGP11.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 ReadOnlyCollect ion 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
ReadOnlyCollect ion 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******* *******@TK2MSFT NGP11.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 ReadOnlyCollect ion 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
ReadOnlyCollect ion 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
7000
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 XmlSerializer will only serialize the collection items - with the default root as ArrayofMyItems etc. My custom collection class has some additional public properties that I would like to include in the serialization above the items element array (in
0
4065
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). Is there a way of using a custom indexer (for example Sensors) that does *not* need to loop through each item in the collection and compare them?
8
3185
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 when the control is painted or resized. When the control is drawn it draws also the items found in the collection. So far so good.... I have 3 questions which I'm unable to find a solution
1
1408
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 all possible widgets will be displayed on a page (using VB.NET/code behind). I plan to populate a custom collection/class with a list of all possible widgets. The class will include a method that returns the required subset. Of course the logic...
21
2094
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 string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns' I would get the following value Terry,Burns.
6
2333
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 having to do a httpwebreqeust call.
19
4910
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 exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
4
5888
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. I have then created a custom collection for this custom entity which naturally inherits CollectionBase and implements IBindingList. When I bind my custom collection to a DataGridView and started editing, it works correctly only up to the...
7
5514
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, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the default behavior and then create an overload as IndexOf(int index, ProductSearchCriteria criteria)...
0
8586
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9004
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.