473,403 Members | 2,293 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,403 software developers and data experts.

Custom Collection Types

Okay something has been driving me crazy.

I see in the MSDN documentation that ToolBar.ToolBarButtonCollection
implements the IList interface.

The I look at members in the ToolBars.Buttons collection like:
public void Add(ToolBarButton button);
public ToolBarButton this[int index];

which don't implement the interface at all. The interface forces Add to take
an object and the indexer to return an object.

I guess what I am getting at is can I make my own custom collection class
that doesn't strictly implement the IList interface but just has methods
with the names of the IList interface, and then will it still work in the
designer. And Why does the documentation say that collections like
ToolBarButtonCollection implement IList when they really don't? Or am I
missing something else?

thanks,
Adam dR.
Nov 16 '05 #1
4 3539

You do not have to implement all of the interfaces properties and methods as
public members. The interface methods and properties could be declared with
private or friend scope so that you do not see them directly when working
with the ToolBarButtonCollection. Here they have used strongly-typed Add
method and Item properties as public to prevent users passing the wrong type
of object. You can cast a ToolBarButtonCollection to an IList and see that
all the properties and methods are there and callable because you have
access to the interface definition even thought they are not visible through
the ToolBarButtonCollection object.

Hope this helps

Robby
"Adam Dockter" <ad**@cu.net> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Okay something has been driving me crazy.

I see in the MSDN documentation that ToolBar.ToolBarButtonCollection
implements the IList interface.

The I look at members in the ToolBars.Buttons collection like:
public void Add(ToolBarButton button);
public ToolBarButton this[int index];

which don't implement the interface at all. The interface forces Add to
take
an object and the indexer to return an object.

I guess what I am getting at is can I make my own custom collection class
that doesn't strictly implement the IList interface but just has methods
with the names of the IList interface, and then will it still work in the
designer. And Why does the documentation say that collections like
ToolBarButtonCollection implement IList when they really don't? Or am I
missing something else?

thanks,
Adam dR.

Nov 16 '05 #2
I Tried what you were saying about make some of the member private or friend
and there is no friend accessor level and when I try to make one of the
IList members internal or private I get the compiler error:

MyCollection.cs(27): 'MyCollection' does not implement interface member
'System.Collections.IList.this[int]'. 'MyCollection.this[int]' is either
static, not public, or has the wrong return type.

It requires me to make them public. Thanks for the suggestion, maybe I am
still doing something wrong. Any other ideas?

"Adam Dockter" <ad**@cu.net> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Okay something has been driving me crazy.

I see in the MSDN documentation that ToolBar.ToolBarButtonCollection
implements the IList interface.

The I look at members in the ToolBars.Buttons collection like:
public void Add(ToolBarButton button);
public ToolBarButton this[int index];

which don't implement the interface at all. The interface forces Add to take an object and the indexer to return an object.

I guess what I am getting at is can I make my own custom collection class
that doesn't strictly implement the IList interface but just has methods
with the names of the IList interface, and then will it still work in the
designer. And Why does the documentation say that collections like
ToolBarButtonCollection implement IList when they really don't? Or am I
missing something else?

thanks,
Adam dR.

Nov 16 '05 #3

Do you have a code snippet?
"Adam Dockter" <ad**@cu.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I Tried what you were saying about make some of the member private or
friend
and there is no friend accessor level and when I try to make one of the
IList members internal or private I get the compiler error:

MyCollection.cs(27): 'MyCollection' does not implement interface member
'System.Collections.IList.this[int]'. 'MyCollection.this[int]' is either
static, not public, or has the wrong return type.

It requires me to make them public. Thanks for the suggestion, maybe I am
still doing something wrong. Any other ideas?

"Adam Dockter" <ad**@cu.net> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Okay something has been driving me crazy.

I see in the MSDN documentation that ToolBar.ToolBarButtonCollection
implements the IList interface.

The I look at members in the ToolBars.Buttons collection like:
public void Add(ToolBarButton button);
public ToolBarButton this[int index];

which don't implement the interface at all. The interface forces Add to

take
an object and the indexer to return an object.

I guess what I am getting at is can I make my own custom collection class
that doesn't strictly implement the IList interface but just has methods
with the names of the IList interface, and then will it still work in the
designer. And Why does the documentation say that collections like
ToolBarButtonCollection implement IList when they really don't? Or am I
missing something else?

thanks,
Adam dR.


Nov 16 '05 #4
I think I have it figured out.

You can implement the IList member like this, with not accessor level and
full qualified back to the interface.

int System.Collections.IList.Add(object value){...}
object System.Collections.IList.this[int index]{...}

Then you can defien your own types to your new collection:

public int Add(MyObject value){...}
public object this[int index]{...}

thanks for your help.
"Robby" <ed****@not.my.email.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Do you have a code snippet?
"Adam Dockter" <ad**@cu.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I Tried what you were saying about make some of the member private or
friend
and there is no friend accessor level and when I try to make one of the
IList members internal or private I get the compiler error:

MyCollection.cs(27): 'MyCollection' does not implement interface member
'System.Collections.IList.this[int]'. 'MyCollection.this[int]' is either
static, not public, or has the wrong return type.

It requires me to make them public. Thanks for the suggestion, maybe I am still doing something wrong. Any other ideas?

"Adam Dockter" <ad**@cu.net> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Okay something has been driving me crazy.

I see in the MSDN documentation that ToolBar.ToolBarButtonCollection
implements the IList interface.

The I look at members in the ToolBars.Buttons collection like:
public void Add(ToolBarButton button);
public ToolBarButton this[int index];

which don't implement the interface at all. The interface forces Add to

take
an object and the indexer to return an object.

I guess what I am getting at is can I make my own custom collection class that doesn't strictly implement the IList interface but just has methods with the names of the IList interface, and then will it still work in the designer. And Why does the documentation say that collections like
ToolBarButtonCollection implement IList when they really don't? Or am I missing something else?

thanks,
Adam dR.



Nov 16 '05 #5

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

Similar topics

0
by: Thomas D. | last post by:
Situation: --------------------------- I have an 'export'-wrapper to my regular objects. For each regular object there is also an export object. An export object derives from the regular object...
9
by: craig | last post by:
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...
3
by: hellrazor | last post by:
Hi there, I'm trying to consume a web-service that is supposed to return a collection of a custom object. The web-service was not created with C# or VS.net. It was created with IBM VisualAge...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
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...
2
by: =?Utf-8?B?Y3Nz?= | last post by:
I am new to ASP.net webservice and have a quesiton. Is is possible to pass custom object to a web service (using VB 2005)? My custom object will look like this Public Class Myclass Public...
4
by: =?Utf-8?B?cmtvemxpbg==?= | last post by:
Is it possible to remotely host custom types? Some background... We have an application that uses custom user controls as 'templates' for entering certain kinds of data. The application is...
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
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...
0
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,...
0
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...

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.