例如我们有一个 double 的多维数组
double[,] d = new double[1,2];
d.GetType()
返回 {Name = "Double[,]"FullName = "System.Double[,]"}
d[0,0]
被编译为 call instance float64 float64[0..., 0...]::Get(int32, int32)
IL
System.Double[,]
类型的源代码是如何生成的?
它是在 CLR 中烘焙还是由 Roslyn 负责生成?
最佳答案
您要查找的内容在 arraynative.cpp 中和 arraynative.h .
从Array.cs开始:
public unsafe Object GetValue(params int[] indices)
使用
fixed(int* pIndices = indices)
InternalGetReference(&elemref, indices.Length, pIndices);
InternalGetReference()
在哪里(同一个文件):
[MethodImplAttribute(MethodImplOptions.InternalCall)]
// reference to TypedReference is banned, so have to pass result as pointer
private unsafe extern void InternalGetReference(void * elemRef, int rank, int * pIndices);
MethodImplOptions.InternalCall
在 ecalllist.h 中定义(记住这个文件...它包含所有的MethodImplOptions.InternalCall
,所以它很有用)(如果你不记得文件名,你可以简单地搜索InternalGetReference
在 github 中...包含该词的文件不多):
FCFuncElement("InternalGetReference", ArrayNative::GetReference)
所以你必须寻找 ArrayNative
,它在我链接的两个文件中。
关于c# - C#中多维数组的源码是如何生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35913231/