List<T> inheritance

J

Joanna Carter [TeamB]

"Fabio Z" <[email protected]> a écrit dans le message de (e-mail address removed)...

| If I should say it all, I should implement an interface, but not IList<T>,
| because I need a object that doesn't publish Add, Remove, Clear that are
| managed internally (I'm thinking about IEnumerable<T>).

If you don't want to publish those methods, then look at ICollection, the
non-generic interface. All the methods you want to hide are those that
belong to ICollection<T> so, by using the non-generic interface, you should
get what you need.

Joanna
 
F

Fabio

"Joanna Carter [TeamB]" <[email protected]> ha scritto nel messaggio

If you don't want to publish those methods, then look at ICollection, the
non-generic interface. All the methods you want to hide are those that
belong to ICollection<T> so, by using the non-generic interface, you
should
get what you need.

You're right, but I'll loose the strong-typing :(
 
J

Joanna Carter [TeamB]

"Fabio" <[email protected]> a écrit dans le message de (e-mail address removed)...

| You're right, but I'll loose the strong-typing :(

Since ICollection doesn't expose any members that access the items in the
list, this is very "strongly typed" :)

You are allowed to write your own interfaces you know :) So, why don't you
derive your own interface from ICollection ?

Something like :

public IReadOnlyCollection<T> : ICollection
{
T this[int index] { get; set; }
}

Then you get to write a class that implements this interface like this :

public class ItemCollection<T> : IReadOnlyCollection<T> where T : Item
{
...
}

This will then also have to implement IEnumerable by inheritance.

Does this help ?

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top