Example #1
0
        public override TCollection GetNext()
        {
            var length = _randomLengthGenerator.GetNext();

            if (_collectionType.IsArray)
            {
                // Create instance of collection
                var arrayType = _typeParameter.MakeArrayType();

                dynamic instance = Activator.CreateInstance(arrayType, length);

                if (_randomValueGenerator != null)
                {
                    dynamic generator = _randomValueGenerator;

                    for (int i = 0; i < length; i++)
                    {
                        var value = generator.GetNext();
                        if (TypeCheckExtensions.IsTypeNumericOrChar(_typeParameter))
                        {
                            dynamic convertedValue = Convert.ChangeType(value, _typeParameter);
                            instance[i] = convertedValue;
                        }
                        else
                        {
                            instance[i] = value;
                        }
                    }
                }
                else
                {
                    return(default);