Assembly: MbUnit (in MbUnit.dll) Version: 3.3.0.0 (3.3.610.0)
Syntax
| C# |
|---|
public ColumnAttribute( params Object[] values ) |
| Visual Basic (Declaration) |
|---|
Public Sub New ( _ ParamArray values As Object() _ ) |
Parameters
- values
- Type: array<
System..::.Object
>[]()[]
The array of values in the column.
Remarks
There exist two ambiguities in the use of this attribute that result from how the C# compiler handles functions that accept a variable number of arguments.
Case 1: If there is only 1 argument and its value is null, the compiler will pass a null array reference to the attribute constructor. Since the value array cannot be null, the attribute will assume that you meant to create an array consiting of a single null.
// Example of case #1. // The attribute will assume that you intended to pass in a single null value. [Test] [Column(null)] public void Test(object value) { Assert.IsNull(value); }
Case 2: If there is only 1 argument and its value is an object array, the compiler will pass the array itself as the argument values. Unfortunately, the attribute constructor cannot distinguish this case from the usual case when multiple arguments are present. So you need to disambiguate this case explicitly.
// Example of case #2. // The attribute will treat both of the following declarations equivalently // contrary to what we probably intend. [Column(new object[] { 1, 2, 3 })] [Column(1, 2, 3)]
To fix this case, you must provide explicit disambiguation. (We cannot do it automatically based on the number of method parameters provided because the row attribute can be applied to other elements besides methods and its contents might be consumed in other ways.)
// Example of case #2, disambiguated to define a column that contains only an array of values. [Test] [Column(new object[] { new object[] { 1, 2, 3 })] public void Test(object[] values) { ArrayAssert.AreElementsEqual(new object[] { 1, 2, 3 }, values); }
