NOV Data Structures are as clean as possible from .NET interface dependencies. In some cases however, it is required to wrap an implementation of a specific NOV Data Structures interface and expose it as a .NET interface and vice-versa. This wrapping process is known as adaptation, since it uses the adapter design pattern - an intermediate adapter object is created that implements the target interface and takes as input the adapted interface. In NOV the adaptation to/from NOV Data Structures interfaces is exposed by static methods of the NCLRAdapt<T> static class.
The following example demonstrates how to use a foreach loop, to iterate through the items of a NList<T>.
NCLRAdapt Sample |
Copy Code
|
---|---|
NList<string> fruits = new NList<string>(); fruits.Add("Apple"); fruits.Add("Orange"); fruits.Add("Banana"); foreach (string fruit in NCLRAdapt<string>.ToIEnumerable(fruits)) { Console.WriteLine(fruit); } |
The following table summarizes the currently possible conversions exposed by the methods of the NCLRAdapt<T> static class:
Function | Description |
NOV to .NET |
|
IEnumerator<T> ToIEnumerator(INIterator<T> it) |
Adapts an INIterator<T> as an IEnumerator<T> |
IEnumerable<T> ToIEnumerable(INIterable<T> it) |
Adapts an INIterable<T> as an IEnumerable<T> |
.NET to NOV |
|
INIterator<T> ToINIterator(IEnumerator<T> en) |
Adapts an IEnumerator<T> as an INIterator<T> |
INIterable<T> ToINIterable(IEnumerable<T> enumerable) |
Adapts an IEnumerable<T> as an INIterable<T> |
INArray<T> ToINArray(T[] arr) |
Adapts a .NET one dimensional array as INArray<T> |