Can I initialize a C# attribute with an array or other variable number of arguments?

后端 未结 7 2173
生来不讨喜
生来不讨喜 2020-11-28 05:56

Is it possible to create an attribute that can be initialized with a variable number of arguments?

For example:

[MyCustomAttribute(new int[3,4,5])]           


        
7条回答
  •  醉梦人生
    2020-11-28 06:21

    Yes, but you need to initialize the array that you are passing in. Here is an example from a row test in our unit tests that tests a variable number of command line options;

    [Row( new[] { "-l", "/port:13102", "-lfsw" } )]
    public void MyTest( string[] args ) { //... }
    

提交回复
热议问题