0

I'm getting a parameter count mismatch with NBuilder, basically trying to Build up a List of Lists, can't seem to find any examples using NBuilder to do this:

public class MyClass
{
   public IEnumerable<IEnumerable<int>> Matrix { get; set; }
}

_myClass.Matrix = Builder<List<int>>.CreateListOfSize(10).Build();

System.Reflection.TargetParameterCountException : Parameter count mismatch.
Mark W
  • 3,879
  • 2
  • 37
  • 53

2 Answers2

1

You can't create list of lists with NBuilder - it fails to initialize properties of generic type parameter, which is List<int> in your case. NBuilder finds indexer property on list and tries to initialize it's value this way (you can find source code here):

propertyInfo.SetValue(obj, value, null);

But for indexer property index should be passed in last parameter. That's causes exception Parameter count mismatch.


Here is how you can initialize matrix:

_myClass.Matrix = Enumerable.Repeat(Enumerable.Range(0, 100).ToList(), 100);

Or with NBuilder

_myClass.Matrix = Enumerable.Repeat(Builder<int>.CreateListOfSize(100).Build(), 100);
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
0

Ok, can't use NBuilder from what I can tell, someone correct me, but this solved the problem,

// basically create a matrix of 100x100 for instance
var innerList = Enumerable.Repeat(0, 100);
var list = Enumerable.Repeat(innerList, 100);
_myClass.Matrix = list;
Mark W
  • 3,879
  • 2
  • 37
  • 53