Description
I want to be able to pass a collection to this method and have it return between X (minimum) and Y (maximum) items.
The method also accept an opt-in for returning NULL when the amount of picked items is zero.
LINQPad Code Example
var participantsEmpty = new Faker().PickRandom(people, 0, 5).ToList();
This would return between zero and five items from the people collection. The method will return an empty collection when the amount of items that will be returned is zero.
var participantsNull = new Faker().PickRandom(people, 0, 5, true).ToList();
This would return between zero and five items from the people collection. As we supply true as the third parameter, the method will return NULL when the amount of items that will be returned is zero.
What alternatives have you considered?
The following could be used as a workaround:
var faker = new Faker();
var attendeeCount = faker.Random.Number(2, 8);
var participantsEmpty = faker.PickRandom(people, attendeeCount).ToList();
someObject.Participants = participantsEmpty.Count == 0 ? NULL : participantsEmpty
Could you help with a pull-request?
Yes