public void Bind(PropertyInfo property, IBindingContext context)
        {
            var type = property.PropertyType;
            var itemType = type.GetGenericArguments()[0];
            if (type.IsInterface)
            {
                type = _collectionTypeProvider.GetCollectionType(type, itemType);
            }

            object collection = Activator.CreateInstance(type);
            var collectionType = collection.GetType();

            Func<object, bool> addToCollection = obj =>
                {
                    if (obj != null)
                    {
                        var addMethod = _addMethods[collectionType];
                        addMethod.Invoke(collection, new[] {obj});
                        return true;
                    }
                    return false;
                };

            var formatString = property.Name + "[{0}]";

            int index = 0;
            string prefix;
            do
            {
                prefix = formatString.ToFormat(index);
                index++;
            } while (addToCollection(context.BindObject(prefix, itemType)));

            property.SetValue(context.Object, collection, null);
        }
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                if (_conversionPropertyBinder.CanBeParsed(property.PropertyType))
                {
                    bool convertedAsIs = context.Data.ValueAs <string>(property.Name, value => _conversionPropertyBinder.Bind(property, context));
                    if (convertedAsIs)
                    {
                        return;
                    }
                }

                var collection = property.GetValue(context.Object, null) as ICollection <T>;

                if (collection == null)
                {
                    collection = new List <T>();
                    property.SetValue(context.Object, collection, null);
                }

                context.GetEnumerableRequests(property.Name).Each(request =>
                {
                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(request, typeof(T), @object => { collection.Add((T)@object); });
                });
            }
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            if (context.Object == null)
            {
                return;
            }

            Type entityType = context.Object.GetTrueType();

            // If there is no Extends<> for the entity type, do nothing
            if (!ExtensionProperties.HasExtensionFor(entityType))
            {
                return;
            }

            Type extensionType = ExtensionProperties.ExtensionFor(entityType);

            // direct the FubuMVC model binding to resolve an object of the
            // extensionType using "entityType.Name" as the prefix on the form data,
            // and place the newly created object using the specified property
            var childRequest = context.GetSubRequest(property.Name);

            context.BindObject(childRequest, property.PropertyType, o =>
            {
                property.SetValue(context.Object, o, null);
            });
        }
예제 #4
0
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                var requests = context.GetEnumerableRequests(property.Name).ToList();

                // TODO -- need an end to end test on this behavior
                if (!requests.Any())
                {
                    return;
                }

                var data = new T[requests.Count];

                for (int i = 0; i < requests.Count; i++)
                {
                    var requestData = requests[i];

                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(requestData, typeof(T), o =>
                    {
                        data[i] = (T)o;
                    });
                }

                property.SetValue(context.Object, data, null);
            }
예제 #5
0
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                var collection = property.GetValue(context.Object, null) as ICollection <T>;

                if (collection == null)
                {
                    collection = new List <T>();
                    property.SetValue(context.Object, collection, null);
                }

                context.GetEnumerableRequests(property.Name).Each(request =>
                {
                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(request, typeof(T), @object => { collection.Add((T)@object); });
                });
            }
예제 #6
0
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            var type     = property.PropertyType;
            var itemType = type.GetGenericArguments()[0];

            if (type.IsInterface)
            {
                type = _collectionTypeProvider.GetCollectionType(type, itemType);
            }

            object collection     = Activator.CreateInstance(type);
            var    collectionType = collection.GetType();

            Func <object, bool> addToCollection = obj =>
            {
                if (obj != null)
                {
                    var addMethod = _addMethods[collectionType];
                    addMethod.Invoke(collection, new[] { obj });
                    return(true);
                }
                return(false);
            };

            //TODO: work in the IElementNamingConvention somehow

            var formatString = property.Name + "[{0}]";

            int    index = 0;
            string prefix;

            do
            {
                prefix = formatString.ToFormat(index);
                index++;
            } while (addToCollection(context.BindObject(prefix, itemType)));

            property.SetValue(context.Object, collection, null);
        }
        public void Bind(PropertyInfo property, IBindingContext context)
        {
            if (context.Object == null) return;

            Type entityType = context.Object.GetTrueType();

            // If there is no Extends<> for the entity type, do nothing
            if (!ExtensionProperties.HasExtensionFor(entityType))
            {
                return;
            }

            Type extensionType = ExtensionProperties.ExtensionFor(entityType);

            // direct the FubuMVC model binding to resolve an object of the
            // extensionType using "entityType.Name" as the prefix on the form data,
            // and place the newly created object using the specified property
            var childRequest = context.GetSubRequest(property.Name);
            context.BindObject(childRequest,property.PropertyType, o =>
            {
                property.SetValue(context.Object, o, null);
            });
        }
예제 #8
0
            public void FillValues(PropertyInfo property, IBindingContext context)
            {
                if (_conversionPropertyBinder.CanBeParsed(property.PropertyType))
                {
                    bool convertedAsIs = context.Data.ValueAs <string>(property.Name, value => _conversionPropertyBinder.Bind(property, context));
                    if (convertedAsIs)
                    {
                        return;
                    }
                }

                var requests = context.GetEnumerableRequests(property.Name).ToList();

                // TODO -- need an end to end test on this behavior
                if (!requests.Any())
                {
                    return;
                }

                var data = new T[requests.Count];

                for (int i = 0; i < requests.Count; i++)
                {
                    var requestData = requests[i];

                    context.Logger.PushElement(typeof(T));

                    // TODO -- got to add the BindResult to context to store it later
                    context.BindObject(requestData, typeof(T), o =>
                    {
                        data[i] = (T)o;
                    });
                }

                property.SetValue(context.Object, data, null);
            }