我在哪里可以找到获取,设置和地址的方法在.NET多维的System.Array实例的信息?多维、我在、可以找到、实例

2023-09-04 09:25:28 作者:浅浅々—吻印

的System.Array 的作为所有基类阵列中的公共语言运行时(CLR)。据本文:

System.Array serves as the base class for all arrays in the Common Language Runtime (CLR). According to this article:

对于每一个具体的数组类型,[中]运行时增加了三个特殊的方法:获取 / 设置 / 地址

For each concrete array type, [the] runtime adds three special methods: Get/Set/Address.

而事实上,如果我拆开这个C#code,

and indeed if I disassemble this C# code,

int[,] x = new int[1024,1024];
x[0,0] = 1;
x[1,1] = 2;
x[2,2] = 3;
Console.WriteLine(x[0,0]);
Console.WriteLine(x[1,1]);
Console.WriteLine(x[2,2]);

到CIL我得到的,

into CIL I get,

IL_0000:  ldc.i4     0x400
IL_0005:  ldc.i4     0x400
IL_000a:  newobj     instance void int32[0...,0...]::.ctor(int32,
                                                         int32)
IL_000f:  stloc.0
IL_0010:  ldloc.0
IL_0011:  ldc.i4.0
IL_0012:  ldc.i4.0
IL_0013:  ldc.i4.1
IL_0014:  call       instance void int32[0...,0...]::Set(int32,
                                                       int32,
                                                       int32)
IL_0019:  ldloc.0
IL_001a:  ldc.i4.1
IL_001b:  ldc.i4.1
IL_001c:  ldc.i4.2
IL_001d:  call       instance void int32[0...,0...]::Set(int32,
                                                       int32,
                                                       int32)
IL_0022:  ldloc.0
IL_0023:  ldc.i4.2
IL_0024:  ldc.i4.2
IL_0025:  ldc.i4.3
IL_0026:  call       instance void int32[0...,0...]::Set(int32,
                                                       int32,
                                                       int32)
IL_002b:  ldloc.0
IL_002c:  ldc.i4.0
IL_002d:  ldc.i4.0
IL_002e:  call       instance int32 int32[0...,0...]::Get(int32,
                                                        int32)
IL_0033:  call       void [mscorlib]System.Console::WriteLine(int32)
IL_0038:  ldloc.0
IL_0039:  ldc.i4.1
IL_003a:  ldc.i4.1
IL_003b:  call       instance int32 int32[0...,0...]::Get(int32,
                                                        int32)
IL_0040:  call       void [mscorlib]System.Console::WriteLine(int32)
IL_0045:  ldloc.0
IL_0046:  ldc.i4.2
IL_0047:  ldc.i4.2
IL_0048:  call       instance int32 int32[0...,0...]::Get(int32,
                                                        int32)
IL_004d:  call       void [mscorlib]System.Console::WriteLine(int32)

在哪里调用上述获取设置方法,可以清楚地看到。看来这些方法的元数是相关的阵列的维数,这是presumably为什么它们被运行时创建并且不是$ P $对 - 声明。我无法找到关于MSDN及其简单的名字对这些方法的任何信息,使他们能够使用Google的抵抗力。我正在写一个编译器,它支持多维数组语言,所以我想找到有关这些方法,在什么情况下我能指望他们有什么我可以期待他们的签名是一些官方文件。

where the calls to the aforementioned Get and Set methods can be clearly seen. It seems the arity of these methods is related to the dimensionality of the array, which is presumably why they are created by the runtime and are not pre-declared. I couldn't locate any information about these methods on MSDN and their simple names makes them resistant to Googling. I'm writing a compiler for a language which supports multidimensional arrays, so I'd like to find some official documentation about these methods, under what conditions I can expect them to exist and what I can expect their signatures to be.

在我特别想知道它是否可能获得的获取 A 的MethodInfo 对象或设置 Reflection.Emit的的使用,而无需创建一个实例哪种类型和维度来体现,如在链接的例子做了。

In particular, I'd like to know whether its possible to get a MethodInfo object for Get or Set for use with Reflection.Emit without having to create an instance of the array with correct type and dimensionality on which to reflect, as is done in the linked example.

推荐答案

看这里,特别是在页面上段14.2 63-65

Look here, specifically section 14.2 on pages 63-65

http://download.microsoft.com/download/7/3/3/733AD403-90B2-4064-A81E-01035A7FE13C/MS%20Partition%20II.pdf

但外卖,你可以告诉从IL,是他们的getter和setter方法​​与数组处理在给定的索引位置。

But the takeaway, and you can tell from the IL, is that they're the getter and setter methods for dealing with arrays at the given index positions.

•一个get方法,它的序列   INT32参数,一个用于每个   维阵列的,并返回一个   值类型为元素类型   该阵列。此方法用于   访问数组的特定元素   这里的参数指定索引   在每个层面,首先是   第一元件,是   回来了。

• A Get method that takes a sequence of int32 arguments, one for each dimension of the array, and returns a value whose type is the element type of the array. This method is used to access a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element to be returned.

•一组方法,它接受一个序列   的INT32参数,一个用于每个   维阵列的,随后是   值类型为元素类型   该阵列。设置的返回类型   是无效的。这种方法用于设置一个   该数组,其中的特定元素   该参数指定的索引   每个维,与开始   元件的第一,可被设定和   最后一个参数指定的值   要被存储到目标元素

• A Set method that takes a sequence of int32 arguments, one for each dimension of the array, followed by a value whose type is the element type of the array. The return type of Set is void. This method is used to set a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element to be set and the final argument specifies the value to be stored into the target element.

•一个地址的方法,需要一个   序列的INT32参数,一个用于   该阵列的每个维度,并且具有   返回类型为托管指针   对数组的元素类型。本   方法用于返回一个管理   指针的特定元素   数组,其中的参数指定   索引到每一个层面,开始   与第一,其元素的,   地址是要被返回。

• An Address method that takes a sequence of int32 arguments, one for each dimension of the array, and has a return type that is a managed pointer to the array’s element type. This method is used to return a managed pointer to a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element whose address is to be returned.

编辑:这是使用文档的页码页63-65。 73-75在实际的PDF。

That's pages 63-65 using the document's page numbering. 73-75 in the actual PDF.