예제 #1
0
        protected virtual object GetValue(BindingContext context, int index)
        {
            var collection = context.Object as IList<object>;

            return collection.ElementAtOrDefault(index);
        }
예제 #2
0
        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;
        }
예제 #3
0
        protected virtual object GetValue(BindingContext context, int index)
        {
            var collection = context.Object as IList <object>;

            return(collection.ElementAtOrDefault(index));
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }