private static void BuildClass(ClassDef cls, Queue<ClassDef> nestedTypesPool, int level) { int propsCount = RandomGen.PickNumber(MinNumberOfProperties, MaxNumberOfProperties); for (int i = 0; i < propsCount; i++) { NEWPROP: string propName = RandomGen.GetRandomPropertyName(); switch (RandomGen.PickNumber(4)) { case 0: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "string", }); break; case 1: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "int", }); break; case 2: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "bool", }); break; case 3: if (nestedTypesPool.Count == 0 || !RandomGen.IsLucky(10 - level) || level > MaxTypeDepth) goto NEWPROP; var nestedCls1 = nestedTypesPool.Dequeue(); cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = nestedCls1.Name, }); BuildClass(nestedCls1, nestedTypesPool, level + 1); break; case 4: if (nestedTypesPool.Count == 0 || !RandomGen.IsLucky(10 - level) || level > MaxTypeDepth) goto NEWPROP; var nestedCls2 = nestedTypesPool.Dequeue(); cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "ICollection<" + nestedCls2.Name + ">", }); BuildClass(nestedCls2, nestedTypesPool, level + 1); break; default: throw new ArgumentOutOfRangeException(); } } }
private static void BuildClass(ClassDef cls, Queue <ClassDef> nestedTypesPool, int level) { int propsCount = RandomGen.PickNumber(MinNumberOfProperties, MaxNumberOfProperties); for (int i = 0; i < propsCount; i++) { NEWPROP: string propName = RandomGen.GetRandomPropertyName(); switch (RandomGen.PickNumber(4)) { case 0: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "string", }); break; case 1: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "int", }); break; case 2: cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "bool", }); break; case 3: if (nestedTypesPool.Count == 0 || !RandomGen.IsLucky(10 - level) || level > MaxTypeDepth) { goto NEWPROP; } var nestedCls1 = nestedTypesPool.Dequeue(); cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = nestedCls1.Name, }); BuildClass(nestedCls1, nestedTypesPool, level + 1); break; case 4: if (nestedTypesPool.Count == 0 || !RandomGen.IsLucky(10 - level) || level > MaxTypeDepth) { goto NEWPROP; } var nestedCls2 = nestedTypesPool.Dequeue(); cls.Properties.Add(new ClassDef.PropertyDef { Name = propName, Type = "ICollection<" + nestedCls2.Name + ">", }); BuildClass(nestedCls2, nestedTypesPool, level + 1); break; default: throw new ArgumentOutOfRangeException(); } } }