private object BindDictionaryModel(string prefix, object model, Type dictionaryType) { List <KeyValuePair <object, object> > list = new List <KeyValuePair <object, object> >(); bool numericIndex; IEnumerable <string> indexes = GetIndexes(prefix, out numericIndex); Type[] genericArguments = dictionaryType.GetGenericArguments(); Type keyType = genericArguments[0]; Type valueType = genericArguments[1]; foreach (var index in indexes) { string indexPrefix = prefix + "[" + index + "]"; if (!this.ValueProvider.ContainsPrefix(indexPrefix) && numericIndex) { break; } string keyPrefix = indexPrefix + ".Key"; string valulePrefix = indexPrefix + ".Value"; list.Add(new KeyValuePair <object, object>(BindModel(keyType, keyPrefix), BindModel(valueType, valulePrefix))); } if (list.Count == 0) { return(null); } ReplaceHelper.ReplaceDictionary(keyType, valueType, model, list); return(model); }
private object BindCollectionModel(string prefix, object model, Type enumerableType) { List <object> list = new List <object>(); bool numericIndex; IEnumerable <string> indexes = GetIndexes(prefix, out numericIndex); Type elementType = enumerableType.GetGenericArguments()[0]; foreach (var index in indexes) { string indexPrefix = prefix + "[" + index + "]"; if (!this.ValueProvider.ContainsPrefix(indexPrefix) && numericIndex) { break; } list.Add(BindModel(elementType, indexPrefix)); } if (list.Count == 0) { return(null); } ReplaceHelper.ReplaceCollection(elementType, model, list); return(model); }