c# - C#中多维数组的源码是如何生成的

标签 c# .net multidimensional-array roslyn coreclr

例如我们有一个 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.InternalCallecalllist.h 中定义(记住这个文件...它包含所有的MethodImplOptions.InternalCall,所以它很有用)(如果你不记得文件名,你可以简单地搜索InternalGetReference 在 github 中...包含该词的文件不多):

FCFuncElement("InternalGetReference", ArrayNative::GetReference)

所以你必须寻找 ArrayNative,它在我链接的两个文件中。

关于c# - C#中多维数组的源码是如何生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35913231/

相关文章:

c# - 在 IIS6 上使用 Decimal In Route 进行路由

c# - 程序是由用户打开的还是从 Windows 注册表启动的?

java - 在java中搜索二维数组中的一系列值

php - 当天的项目

c# - 使用 WCF 正确标记 DataContract 以进行反序列化

c# - 网格和列表框有一些我无法摆脱的边框

c# - 客户端从 cosmos db 中存储的延续 token 在哪里以及如何维护

c# - 序列化数组时如何使用 XmlAttributeOverrides?

python - 对两个 NumPy 数组中的正元素和负元素求和

c# - .NET (C#) 窗口最小化事件