Modify old style .NET 1.1 object collections to support LINQ query

  • Thread starter Thread starter Olivier Matrot
  • Start date Start date
O

Olivier Matrot

Hello,
I'm still using old style strongly typed collections (derived from
CollectionBase .NET 1.1) and I would like to be able to query in memory
collection with LINQ in the future. I also would like to improve performance
of the collection avoiding boxing/unboxing of objects during access of items
in the collection.
Could you please point me to the right direction ?
TIA.
 
Olivier,

The only thing that you will have to do is implement IEnumerable<T>
where T is the type that your collection holds. That will make it
accessible to LINQ.

Hope this helps.
 
Nicholas,
Thanks for that.
But my concern is also to improve performance. CollectionBase stores
"objects", so we need to cast from my type to object and vice versa each
time an item is accessed. Sure there is a better solution by replacing
CollectionBase ??

Nicholas Paldino said:
Olivier,

The only thing that you will have to do is implement IEnumerable<T>
where T is the type that your collection holds. That will make it
accessible to LINQ.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Olivier Matrot said:
Hello,
I'm still using old style strongly typed collections (derived from
CollectionBase .NET 1.1) and I would like to be able to query in memory
collection with LINQ in the future. I also would like to improve
performance of the collection avoiding boxing/unboxing of objects during
access of items in the collection.
Could you please point me to the right direction ?
TIA.
 
Olivier,

If the type that is being stored in your collection is a value type,
then yes, you should probably wrap a List<T> of that type, and implement
IEnumerable<T>. If you are returning object types, then the performance of
that cast is not going to make as much difference as unboxing a value type
would make.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Olivier Matrot said:
Nicholas,
Thanks for that.
But my concern is also to improve performance. CollectionBase stores
"objects", so we need to cast from my type to object and vice versa each
time an item is accessed. Sure there is a better solution by replacing
CollectionBase ??

Nicholas Paldino said:
Olivier,

The only thing that you will have to do is implement IEnumerable<T>
where T is the type that your collection holds. That will make it
accessible to LINQ.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Olivier Matrot said:
Hello,
I'm still using old style strongly typed collections (derived from
CollectionBase .NET 1.1) and I would like to be able to query in memory
collection with LINQ in the future. I also would like to improve
performance of the collection avoiding boxing/unboxing of objects during
access of items in the collection.
Could you please point me to the right direction ?
TIA.
 
I wrote a new class derived from List<T> and IEnumerable<T>. This is working
fine so far.
Thanks for that.

Nicholas Paldino said:
Olivier,

If the type that is being stored in your collection is a value type,
then yes, you should probably wrap a List<T> of that type, and implement
IEnumerable<T>. If you are returning object types, then the performance
of that cast is not going to make as much difference as unboxing a value
type would make.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Olivier Matrot said:
Nicholas,
Thanks for that.
But my concern is also to improve performance. CollectionBase stores
"objects", so we need to cast from my type to object and vice versa each
time an item is accessed. Sure there is a better solution by replacing
CollectionBase ??

Nicholas Paldino said:
Olivier,

The only thing that you will have to do is implement IEnumerable<T>
where T is the type that your collection holds. That will make it
accessible to LINQ.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,
I'm still using old style strongly typed collections (derived from
CollectionBase .NET 1.1) and I would like to be able to query in memory
collection with LINQ in the future. I also would like to improve
performance of the collection avoiding boxing/unboxing of objects
during access of items in the collection.
Could you please point me to the right direction ?
TIA.
 
Back
Top