I am currently browsing decompiled C# IL (with ILSpy) to get an impression on how some of the methods from System.Runtime.InteropServices are (could be) implemented.
When I wanted to check how Marshal.Copy() is implemented, I found out that it only calls CopyToNative(), which is defined as follows:
// System.Runtime.InteropServices.Marshal
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void CopyToNative(object source, int startIndex, IntPtr destination, int length);
Where is it implemented?
Is there any chance to look at its (decompiled) source code?
If not, does anyone have a clue on how it could be implemented?
The
MethodImplAttributeandexternkeyword indicate that this function is internal to the .NET runtime itself. This function is almost certainly implemented in C or C++ in the runtime’s source code.Without access to the runtime’s source code your only real option is to disassemble this particular function and examine the assembly. (Please note that doing this may violate the EULA of your runtime.)
You might consider looking at Mono‘s source code to get a look at one possible implementation.
Marshal.Copy()implementationscopy_to_unmanaged()runtime-internal implementation