private object GenerateArrayWithValues(BuilderContext context) { var type = context.CurrentProperty.PropertyType; var collectionItemType = type.GetElementType() ?? type.GetTypeInfo().GenericTypeArguments.First(); var generator = ValueGeneratorFactory.GetValueGenerator(collectionItemType); var returnValue = Array.CreateInstance(collectionItemType, context.CollectionDegree); context.SetCurrentValueGeneratorType(collectionItemType); for (var i = 0; i < context.CollectionDegree; i++) { returnValue.SetValue(generator.GenerateValue(context), i); } return(returnValue); }
private object GenerateIEnumerableWithValues(BuilderContext context) { var type = context.CurrentProperty.PropertyType; var collectionItemType = type.GetElementType() ?? type.GetTypeInfo().GenericTypeArguments.First(); var genericListType = typeof(List <>).MakeGenericType(collectionItemType); var generator = ValueGeneratorFactory.GetValueGenerator(collectionItemType); var returnValue = (IList)Activator.CreateInstance(genericListType); context.SetCurrentValueGeneratorType(collectionItemType); for (var i = 0; i < context.CollectionDegree; i++) { returnValue.Add(generator.GenerateValue(context)); } return(returnValue); }
public object GenerateValue(BuilderContext context) { var properties = TypeManager.GetProperties(_type); var returnValue = Activator.CreateInstance(_type); foreach (var prop in properties) { if (context.IsInCircularReference(prop.PropertyType)) { continue; } context.SetCurrentProperty(prop); var generator = ValueGeneratorFactory.GetValueGenerator(prop.PropertyType); var value = generator.GenerateValue(context); prop.SetValue(returnValue, value); context.UpdateLastBuildType(prop.PropertyType, value); } return(returnValue); }