public RequiredFieldFactory() { dictionaryBase = new TypeStrategy <IEnumerable <ISchemaRequiredField> >( simpleTypeAction: type => new ISchemaRequiredField[] { new SimpleRequiredField(TypesNamesConsts.DictionaryKeyName, 0, type.FullName) }, collectionTypeAction: type => { var elementTypes = CollectionElementTypeProvider.Get(type); if (elementTypes.Length > 1) { throw new NotSupportedException("Dictionary of dictionary not supported"); } return(GetRequiredFields(elementTypes.First())); }, complexTypeAction: GetRequiredFields); dictionaryRootNameBase = new TypeStrategy <string>( simpleTypeAction: type => type.ToString(), collectionTypeAction: type => { return(TypesNamesConsts.CollectionOf + new CollectionStrategy <string>( dictionaryAction: type1 => throw new NotSupportedException("Dictionary of dictionary not supported"), simpleNonGenericAction: type1 => CollectionElementTypeProvider.Get(type1)[0].Name, complexNonGenericAction: type1 => CollectionElementTypeProvider.Get(type1)[0].Name).Get(type)); }, complexTypeAction: type => type.Name); }
private ISchemaRequiredField GetCollectionField(PropertyInfo child, KeyValuePair <int, AgreementSchemaType> parent) { var collectionStrategy = new CollectionStrategy <ISchemaRequiredField>( dictionaryAction: collectionType => { var keyValueTypes = CollectionElementTypeProvider.Get(collectionType); var keyType = keyValueTypes[0]; var keySchema = dictionaryBase.Get(keyType); var valueType = keyValueTypes[1]; var valueSchema = dictionaryBase.Get(valueType); return(new DictionaryRequiredField(name: child.Name, level: parent.Key, type: string.Format(TypesNamesConsts.DictionaryOf, dictionaryRootNameBase.Get(keyType), dictionaryRootNameBase.Get(valueType)), keyFields: keySchema, valueFields: valueSchema)); }, simpleNonGenericAction: collectionType => { var elementType = CollectionElementTypeProvider.Get(collectionType)[0]; return(new ComplexCollectionRequiredField( name: child.Name, level: parent.Key, type: TypesNamesConsts.CollectionOf + elementType.Name, requiredFields: GetRequiredFields(elementType))); }, complexNonGenericAction: collectionType => { var elementType = CollectionElementTypeProvider.Get(collectionType)[0]; return(new SimpleCollectionRequiredField( name: child.Name, level: parent.Key, type: TypesNamesConsts.CollectionOf + elementType.FullName)); }); return(collectionStrategy.Get(child.PropertyType)); }