1
나는 시험 방법이 있습니다속성 - 값으로 배열을 전달
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.
은 아마 컴파일러가 구별 할수 없어 :
이[TestCase(new string[] { "1", "2", "5" }, Result = true)]
bool AllocateIDsTest1(IEnumerable<string> expected)
{
var target = ...
var actual = target.AllocateIDs(expected);
return actual.SequenceEqual(expected);
}
그러나 나는 컴파일러 오류 다음 생성자 :
TestCase(params object[] args, Named Parameters);
및
,new string[] { "1", "2", "5" }
은 params object[]
및 object
모두로 해석 될 수 있기 때문에.
this post에서 문자열 배열이 컴파일 상수로 전달 될 수 있어야한다는 것을 알고 있습니다.
TestCase
에 문자열 배열을 제공하려면 어떻게해야합니까?
[TestCase("1", "2", "5", Result = true)]
public bool AllocateIDsTest1(params string[] expected)
{
var target = ...
var actual = target.AllocateIDs(expected);
return actual.SequenceEqual(expected);
}
우수 해결 방법 : –
해결 방법조차 없습니다. :-) TestCase를 사용하는 방법입니다. 컴파일러 오류는 배열을 전달했기 때문에 발생하는 것은 아니며 속성에 명시 적으로 허용됩니다. 그것은 new를 사용하여 배열을 동적으로 생성하기 위해 속성 생성자에게 요청하기 때문입니다. C#은 그것을 허용하지 않습니다. – Charlie
@Charlie "속성에 명시 적으로 허용"이라고 할 때, 배열을 속성에 할당하는 것이 얼마나 효과적일까요? '정적'필드를 통해? – HimBromBeere