In a class definition, I implemented IList<T>
to make it look like an array.
// Foo has C++ arrays inside for a
// fast communication with some hardware
public abstract class Foo<T> : IList<T(or uint for a derived class)>
{
public virtual void CopyTo(uint[] array, int arrayIndex)
{
int dL = Length;
if (dL == array.Length)
{
/* needs pinning the target before this?*/
Marshal.Copy(handleForFooUnmanagedArray,
(int[])(object) array,
arrayIndex,
dL - arrayIndex);
return;
}
throw new NotImplementedException();
}
}
so it can do this now:
uint [] bar = new uint[L];
foo.CopyTo(bar,0);
but now I want to make it work like an array with this:
uint [] bar = new uint[L];
bar.CopyTo(foo,0);
so I looked what interfaces an array implements in run-time(here) to find something like a private .CopyFrom
that I thought should be called implicity in `.CopyTo',
- IList
- ICloneable
- ICollection
- IEnumerable
- IStructuralComparable
- IStructuralEquatable
non of these have any .CopyFrom
.
Maybe there is some IntPtr
property as a handle for Marshal
copying in .CopyTo
but I couldn't see it in intellisense.
Question:
How can I find that which method does the .CopyTo
use to get necessary info about target array and what that necessary info would that be? Another method like a .CopyFrom
or a handle pointing to start of target array, or some interpreter intermediate codes stored in somewhere? Is the target array pinned in the process?
Side question:
Do I need to implement some extra methods in IList<T>
on top of important(unknown) ones?
I already implemented toArray
, Count
and []
but I havent done anything for others yet. Then Foo
also has Length
(with a custom interface) but it doesn't belong Array
so an uint[]
may not use it in its CopyTo
.
I'm not experienced with IL so I may not understand if thats the solution but I can look back in time.
Also I tried to implement Array which refuses to be implemented because of being a special class.
Thank you very much for your time.