protected override object PopulateInstance(object instance, IExecuteStrategy executeStrategy)
{
Debug.Assert(instance != null, "instance != null");
var type = instance.GetType();
var internalType = FindEnumerableTypeArgument(type);
var collectionGenericTypeDefinition = typeof(ICollection<string>).GetGenericTypeDefinition();
var collectionType = collectionGenericTypeDefinition.MakeGenericType(internalType);
// Get the Add method
var addMethod = collectionType.GetMethod("Add");
object previousItem = null;
for (var index = 0; index < AutoPopulateCount; index++)
{
var childInstance = CreateChildItem(internalType, executeStrategy, previousItem);
addMethod.Invoke(
instance,
new[]
{
childInstance
});
previousItem = childInstance;
}
return instance;
}