473,715 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CollectionBase Strong Type

I have a Strongly Typed collection ex:

public class MyClassCollecti on : CollectionBase
{
.... implemention ....
}

public class MyClass
{}

Is there a way using reflection to get the type the StronglyTyped collection
"MyClassCollect ion" expects?

Thanks,
--
Don DenUyl
Diamond Systems
Dec 5 '05 #1
2 1346
Don

Not really. You aren't required to implement anything beyond what
CollectionBase implements.

You have two ways of doing this. First, you could get the PropertyInfo
for the indexer and see the type that it returns. This assumes you have
indexers on all of your typed collections. The second is to attach an
attribute to the class which exposes the type that it exposes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Don D" <Do**@discussio ns.microsoft.co m> wrote in message
news:FA******** *************** ***********@mic rosoft.com...
I have a Strongly Typed collection ex:

public class MyClassCollecti on : CollectionBase
{
... implemention ....
}

public class MyClass
{}

Is there a way using reflection to get the type the StronglyTyped
collection
"MyClassCollect ion" expects?

Thanks,
--
Don DenUyl
Diamond Systems

Dec 5 '05 #2
Good idea, becaused we do implement the indexer.

Regards,
--
Don DenUyl
Diamond Systems
"Nicholas Paldino [.NET/C# MVP]" wrote:
Don

Not really. You aren't required to implement anything beyond what
CollectionBase implements.

You have two ways of doing this. First, you could get the PropertyInfo
for the indexer and see the type that it returns. This assumes you have
indexers on all of your typed collections. The second is to attach an
attribute to the class which exposes the type that it exposes.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Don D" <Do**@discussio ns.microsoft.co m> wrote in message
news:FA******** *************** ***********@mic rosoft.com...
I have a Strongly Typed collection ex:

public class MyClassCollecti on : CollectionBase
{
... implemention ....
}

public class MyClass
{}

Is there a way using reflection to get the type the StronglyTyped
collection
"MyClassCollect ion" expects?

Thanks,
--
Don DenUyl
Diamond Systems


Dec 5 '05 #3

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

Similar topics

4
1800
by: Majed | last post by:
hi all i've created a strong named collection which inherits collection base,but when i try to add to it a nullreferenceexception blows. the code is as listed below. do i have to init the list myself. any hints...please! thanks all Public Class NewKeys Inherits BaseCollection
0
1158
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the XmlSerializer (as it is) won't allow you to treat an ICollection (or IEnumerable) object as the root node without using XmlAttributeOverides or sending in a new root attribute with the serializer.
0
2174
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
1
7088
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class and properties derived from this class but will not serialize or deserialize the properties in CollectionBase. Like InnerList, which is a read only property of CollectionBase. How can I serialize and deserialize the InnerList property of...
1
336
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit down and look at it, I'm wondering why it behaves the way it does, and also how to improve its functionality. First, understand the basic format of a type-safe collection:
1
2901
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties related to an invoice -InvoiceCollection: Inherited from Collectionbase class and holds Invoice objects The InvoiceCollection class is as follows:
2
6961
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count, GetEnumerator, and RemoveAt) but the way it implements all the other things you need to override seems overkill and counters the advantage of having an extensible base class. For example, the documentation example implementation of Remove: Public...
4
3460
by: _DS | last post by:
I need to create arrays of a custom data type (which is composed of various strings, ints, the usual). The original was built using CollectionBase. I was thinking about redesigning to use generics, but I realized that DataSets may also work here. I do need to display and edit lists of the items at various places. In the previous version I used a custom ListView for most display purposes. Given that DataSets in VS2005 have so many...
3
2116
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like the below which you sent me previously. So the referenced type for List that will be returned at execution time must be CollectionBase. The compile type for List
0
8820
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8718
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
9332
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
9044
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3174
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
2537
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
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.