protected virtual void BindValue(BindingMemberInfo modelProperty, object obj, BindingContext context) { if (obj == null) { return; } Type dictionaryType = typeof(Dictionary <string, object>); //If the type is a dictionary and the PropertyType isn't then we'll bind. if (obj.GetType() == dictionaryType && modelProperty.PropertyType != dictionaryType) { //We have a sub dictionary, attempt to bind it to the class var model = Bind(obj, modelProperty.PropertyType); modelProperty.SetValue(context.Model, model); } //If both types are collections then we'll bind else if (obj.GetType().IsCollectionOrArray() && modelProperty.PropertyType.IsCollectionOrArray()) { //We have a sub dictionary, attempt to bind it to the class var model = Bind(obj, modelProperty.PropertyType); modelProperty.SetValue(context.Model, model); } else { //Simply set the property modelProperty.SetValue(context.Model, obj); } }
protected virtual void BindValue(BindingMemberInfo modelProperty, object obj, BindingContext context) { if (obj == null) { return; } if (modelProperty.PropertyType.IsAssignableFrom(obj.GetType())) { // Simply set the property modelProperty.SetValue(context.Model, obj); } else { // Cannot directly set the property attempt to bind var model = Bind(obj, modelProperty.PropertyType); modelProperty.SetValue(context.Model, model); } }