private IEnumerable <object> _generatePropertiesPermutation( Type classType, IObjectDefinition objectDefinition = null) { var mutator = new PropertiesMutator(_idName, classType, objectDefinition, _parameterDefinitions); return(mutator.Mutate()); }
private List <List <object> > _generatePermutationList( string definedIdParameterName, PropertyInfo[] propertyInfos, List <IParameterDefinition> parameterDefinitions, IObjectDefinition objectDefinition) { var propertyPermutationLists = new List <List <object> >(); var attributeParameterNameDefinitions = parameterDefinitions.Where(pd => pd.CompareParamName).ToList(); foreach (var prop in propertyInfos) { var inputDefinitionType = string.Empty; var isInputDefinitionTypeNotDefined = (objectDefinition == null) || ((objectDefinition != null) && !objectDefinition.MatcherDictionary.TryGetValue(prop.Name, out inputDefinitionType)); if (objectDefinition == null) { // when there is no object definition, we will check if there is // an attribute parameter name definition that matches with the prop name. // otherwise, we will assign the default prop.PropertyType.Name value if (attributeParameterNameDefinitions.Any(pd => pd.TypeName.Equals(prop.Name))) { inputDefinitionType = attributeParameterNameDefinitions .First(pd => pd.TypeName.Equals(prop.Name)).TypeName.NameList.First(); } else { inputDefinitionType = prop.IsNullableProperty() ? prop.GetNullablePropertyName() : prop.PropertyType.Name; } } else if (isInputDefinitionTypeNotDefined) { // when there is an object definition and cannot be matched, // we will check if there is an attribute parameter name definition // that matches with the prop name. // otherwise, we will assign the default prop.PropertyType.Name value if (attributeParameterNameDefinitions.Any(pd => pd.TypeName.Equals(prop.Name))) { inputDefinitionType = attributeParameterNameDefinitions .First(pd => pd.TypeName.Equals(prop.Name)).TypeName.NameList.First(); } else { inputDefinitionType = prop.IsNullableProperty() ? prop.GetNullablePropertyName() : prop.PropertyType.Name; } } var testInput = (string.Equals(prop.PropertyType.Name, "Guid") || (IsPropertyNameAnId(definedIdParameterName, prop.Name) && isInputDefinitionTypeNotDefined)) ? new List <object> { null } : parameterDefinitions.FirstOrDefault(id => id.TypeName.Equals(inputDefinitionType))?.InputCatalogues; if (testInput == null) { try { // We can't find anything that matches this type. We will try to generate the list of object of this type recursively. var assemblyQualifiedName = prop.PropertyType.AssemblyQualifiedName; var customTypePropertyMutator = new PropertiesMutator(null, prop.PropertyType, _objectDefinition, _parameterDefinitions); testInput = customTypePropertyMutator.Mutate().ToList(); } catch (Exception e) { throw new Exception($"Cannot Found Matching Definition for: { inputDefinitionType }, and have failed to generate permutations with error { e.Message }. Have you assign ObjectDefinition correctly?"); } } propertyPermutationLists.Add(testInput); } return(propertyPermutationLists); }