I am currently learning C #, and I have a situation where I have a class containing ISet. I do not want clients to directly change this set, but most clients only add and delete, and I provide access through my class for this.
However, I have one client who wants to know more about this kit and its contents. I really don't want to mess up the wrapper class itself with a lot of methods for this single client, so I would prefer it to be able to return the set itself in an immutable way.
I found that I could not - well, actually. The only options I have are the following:
Am I missing something? Am I foolish? Is my only way to provide a complete set of accessories on my wrapper? Am I wrong in my initial intention to keep the shell clean for the vast majority of customers?
So, two questions:
Why is there no standard C # interface for the collection? Does this sound like a pretty reasonable requirement?
ReadOnlyCollection ReadOnlyCollection, ReadOnlyList? , , ( ).
# ? , ?
# immutable¹: IEnumerable, .
IEnumerable
, . BCL , , , , .
, (, ) , - , , , (). , / .
IReadOnlyList, IReadOnlySet , . , , 100 .
IReadOnlyList
IReadOnlySet
ReadOnlyCollection , , BCL , , , BCL ( , ). , System.Collections.Generic .
ReadOnlyCollection
System.Collections.Generic
ReadOnlyCollection ReadOnlyCollection, ReadOnlyList? , ( Set).
, BCL , , . ReadOnlyCollection IList, ReadOnlyList.
IList
ReadOnlyList
, , "" , "", , . Set, , ( , Set).
Set
¹ "", . , " ", .
, " " - , .
ISet, , , , , - , .
ISet
, http://blogs.msdn.com/b/jaredpar/archive/2008/04/22/api-design-readonlycollection-t.aspx
, , .net , , , . promises , , , . , promises , .
, , , . ImmutableList<T>, T, , T, . T, .
ImmutableList<T>
T
druthers, , , , ( , ). IAppendable, , IImmutableEnumerable, IEnumerable ( ToImmutable IEnumerable ( IImmutableEnumerable), , . , IEnumerable, . , .
IImmutableEnumerable
ToImmutable