protected virtual object GetValue(BindingContext context, int index) { var collection = context.Object as IList<object>; return collection.ElementAtOrDefault(index); }
protected virtual object GetValue(string propertyName, BindingContext context) { if (context.Object.GetType() == typeof(Dictionary<string, object>)) { var dictionary = (Dictionary<string, object>)context.Object; if (dictionary.ContainsKey(propertyName)) { return dictionary[propertyName]; } } return null; }
protected virtual object GetValue(BindingContext context, int index) { var collection = context.Object as IList <object>; return(collection.ElementAtOrDefault(index)); }
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; } 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); } }