【问题标题】:Mono.Cecil - How to know a method has variable-arguments?Mono.Cecil - 如何知道一个方法有变量参数?
【发布时间】:2019-01-09 14:24:52
【问题描述】:

在 C# 中,我们有 __arglist 关键字,它使方法变量参数如下:

public static void PrintFormat(string format, __arglist) 
{
    ....
}

编译成:

.method public hidebysig static vararg void PrintFormat ( string format ) cil managed 
{
    ....
} 

请注意vararg。那么我们如何知道 Mono.Cecil 中的方法有变量参数呢?

【问题讨论】:

  • this 是否允许您自己回答问题?
  • @JeroenMostert 我很懒 :D。请发布答案。
  • 我差点做到这一点,但后来我决定教你钓鱼。我什至不使用 Mono.Cecil,因为它的答案而受到赞扬感觉越来越糟糕! :-P
  • @JeroenMostert,来吧。
  • @JeroenMostert,好的。

标签: c# cil mono.cecil


【解决方案1】:

@JeroenMostert 指出了这一点。 Source.

public static bool IsVarArg (this IMethodSignature self)
{
    return (self.CallingConvention & MethodCallingConvention.VarArg) != 0;
}

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 2022-07-08
    • 2020-11-11
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多