3

例如,out在 C# 中使用关键字的方法中的参数将显示在元数据签名中,前面带有 & 符号&。我正在尝试为通用方法创建签名,但我不想使用元数据 API 来解决这个问题,它肯定记录在某处吗?

这是我对 Socket 类的 BeginReceiveFrom 的含义的示例:

        System.IAsyncResult([]System.Byte,System.Int32,System.Int32,
    System.Net.Sockets.SocketFlags,&System.Net.EndPoint,
System.AsyncCallback,System.Object)
4

2 回答 2

7
于 2009-07-01T20:35:52.913 回答
2

要声明一个泛型方法,您可以使用!!T来引用泛型参数:

.method public static void Method<T1, T2>(!!T1 arg1, !!T2 arg2) {
    // ...
}

或者您可以使用他们的号码:

.method public static void Method<T1, T2>(!!0 arg1, !!1 arg2)

并调用您提供实例化的通用方法。但是,实例化中引用的类型是被调用的方法,而不是你从哪里调用它:

ldc.i4.1
newobj instance void [mscorlib]System.Object::.ctor()

// !!0 and !!1 refer to the generic parameters of Method<T1, T2>,
// not any generic method this call instruction is part of
call void Method<int32, object>(!!0,!!1)

如果该方法是泛型类型的一部分,您可以使用!T类似的方式指定类型实例化来引用类型参数。请注意,泛型类型在类型名称后有一个 `,后跟泛型参数的数量是惯例:

call instance void MyGenericType`1<int32>::Method(!0)
于 2011-02-21T23:34:07.157 回答