Built-in .NET Framework interfaces, recommendations for creating a custom data structure?

I am implementing an AVL binary tree data structure in C # .NET 2.0 (possibly moving to 3.5). I have this to the extent that it passes my initial unit tests without requiring any framework level interfaces.

But now, just looking at FCL, I see a whole bunch of interfaces, both non-general and general, that I could implement so that my class plays perfectly with language functions and other data structures.

At the moment, the only obvious choice (at least for me) is one of the Enumeration-style interfaces, which allows the caller to use the tree in a foreach loop and possibly later Linq. But which one (or more)?

Here are the interfaces that I am currently considering:

  • IEnumerable and IEnumerable <T>
  • IEnumerator and IEnumerator <T>
  • IComparable and IComparable <T>
  • IComparer and IComparer <T>
  • ICollection and ICollection <T>
  • IEquatable and IEquatable <T>
  • IEqualityComparer and IEqualityComparer <T>
  • Icloneable
  • Iconvertible

Are there any published recommendations, both online and in book format, that contain recommendations on which infrastructure interfaces should be implemented and when?

Obviously, for some interfaces, if you do not want to provide this functionality, just do not implement the entire interface. But there seem to be certain conventions in FCL classes (such as Collection classes) that you might also need to consider when creating custom data structures.

, IComparer IEqualityComparer, IEnumerable IEnumerator? , , - ? ..

, , , .

+3
4

, (ICollection<T> IEnumberable<T>), . IEnumerator IEnumerable (a IEnumerable IEnumerator )

IComparable<T> ( ?), IComparer<T> - .

ICloneable - ( - ).

, , , .

, . (. )

IConvertible - ISerializable.

MSDN , , , .

+2

.
Do, Do Not . MSDN.

+1

, , , , .

, BCL . , , IEnumerable foreach.

. , ICloneable ORM. , , .

: ? BCL ?

( , , IEnumerable IEnumerable, IEnumerator IEnumerator.)

+1

, , , ..

  • , IEnumerable IEnumerable<T> , .
  • , ICloneable , .
  • , .

. :

  • Some interfaces must be implemented in a certain way to avoid "unexpected" behavior in the code that calls them. In particular, equality interfaces must be 100% compatible with each other and with virtual equality methods System.Object.
  • If there is a generic and non-generic version of the same interface, it is always useful to implement both.
0
source

Source: https://habr.com/ru/post/1723882/


All Articles