Determining if a parameter uses “params” using reflection in C#?

前端 未结 3 536
时光取名叫无心
时光取名叫无心 2021-01-17 07:47

Consider this method signature:

public static void WriteLine(string input, params object[] myObjects)
{
    // Do stuff.
}

How can I determ

3条回答
  •  猫巷女王i
    2021-01-17 08:25

    Check the ParameterInfo, if ParamArrayAttribute has been applied to it:

    static bool IsParams(ParameterInfo param)
    {
        return param.GetCustomAttributes(typeof (ParamArrayAttribute), false).Length > 0;
    }
    

提交回复
热议问题