在C#中的反思 [英] Reflection in c#

查看:82
本文介绍了在C#中的反思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void Main()
       {
           int[,] a = new int[3,4];
           a[1, 1] = 10;
           int y = a[1, 1];


现在 ildasm 向我显示以下输出-


Now the ildasm shows me following output-

.method public hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       29 (0x1d)
  .maxstack  4
  .locals init ([0] int32[0...,0...] a,
           [1] int32 y)
  IL_0000:  nop
  IL_0001:  ldc.i4.3
  IL_0002:  ldc.i4.4
  IL_0003:  newobj     instance void int32[0...,0...]::.ctor(int32,
                                                             int32)
  IL_0008:  stloc.0
  IL_0009:  ldloc.0
  IL_000a:  ldc.i4.1
  IL_000b:  ldc.i4.1
  IL_000c:  ldc.i4.s   10
  IL_000e:  call       instance void int32[0...,0...]::Set(int32,
                                                           int32,
                                                           int32)
  IL_0013:  ldloc.0
  IL_0014:  ldc.i4.1
  IL_0015:  ldc.i4.1
  IL_0016:  call       instance int32 int32[0...,0...]::Get(int32,
                                                            int32)
  IL_001b:  stloc.1
  IL_001c:  ret
} // end of method Class5::Main


现在也可以看到三个dimentionl数组的结果


Now see also result for three dimentionl array

public static void Main()
        {
            int[,,] a = new int[3,4,3];
            a[1, 1,2] = 10;
            int y = a[1, 1,2];
        }


现在查看ildasm结果


Now see ildasm result

.method public hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       32 (0x20)
  .maxstack  5
  .locals init ([0] int32[0...,0...,0...] a,
           [1] int32 y)
  IL_0000:  nop
  IL_0001:  ldc.i4.3
  IL_0002:  ldc.i4.4
  IL_0003:  ldc.i4.3
  IL_0004:  newobj     instance void int32[0...,0...,0...]::.ctor(int32,
                                                                  int32,
                                                                  int32)
  IL_0009:  stloc.0
  IL_000a:  ldloc.0
  IL_000b:  ldc.i4.1
  IL_000c:  ldc.i4.1
  IL_000d:  ldc.i4.2
  IL_000e:  ldc.i4.s   10
  IL_0010:  call       instance void int32[0...,0...,0...]::Set(int32,
                                                                int32,
                                                                int32,
                                                                int32)
  IL_0015:  ldloc.0
  IL_0016:  ldc.i4.1
  IL_0017:  ldc.i4.1
  IL_0018:  ldc.i4.2
  IL_0019:  call       instance int32 int32[0...,0...,0...]::Get(int32,
                                                                 int32,
                                                                 int32)
  IL_001e:  stloc.1
  IL_001f:  ret
} // end of method Class5::Main


现在我的问题是
已设置,获取,System.Array的构造方法.使用params int []作为参数
但是如果是反射,则反射不会在反射中显示这样的"Set(params int [])"输出.


Now my question is that
Is set,get,constructor of System.Array class uses params int[] as parameter
But if it is then reflection is not showing such "Set(params int[])"output in reflection.
How this result is possible?

推荐答案

params是C#特定的语言功能:在ILDASM中被视为int,int,int. .因为ILDASM没有(或不需要)这样的构造-它实际上是一种汇编语言,而不是高级语言.
params is a C# specific language feature: it is seen in ILDASM as int, int, int... as ILDASM doesn''t have (or need) such a construct - it is effectively an assembler language, rather than high level.


这篇关于在C#中的反思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆