Exemplo n.º 1
0
        public override PropertyTreeMetaObject BindInitializer(Expression expression, IExpressionContext context, IServiceProvider serviceProvider)
        {
            var values = expression.Evaluate(context);

            if (values == null)
            {
                return(this);
            }
            if (!(values is IEnumerable))
            {
                values = new [] { values };
            }

            var myValues = ReflectionMetaObject.GetAddonElements((IEnumerable)values);
            var addon    = ReflectionMetaObject.FindAddonMethod(ComponentType, myValues);

            if (addon == null)
            {
                var errors = serviceProvider.GetServiceOrDefault(PropertyTreeBinderErrors.Default);
                errors.NoAddMethodSupported(component.GetType(), PropertyTreeBinderImpl.FindFileLocation(serviceProvider));
                return(this);
            }
            foreach (var item in myValues)
            {
                addon.Invoke(Component, new object[] {
                    item
                });
            }
            return(this);
        }
Exemplo n.º 2
0
            void TryAggregation(object current)
            {
                var enumerable = value as IEnumerable;

                if (enumerable == null)
                {
                    return;
                }

                var items = enumerable;

                if (!ReferenceEquals(current, items) && enumerable.GetEnumerator().MoveNext())
                {
                    MethodInfo mi = ReflectionMetaObject.FindAddonMethod(current.GetType(), enumerable);

                    if (mi == null)
                    {
                        throw new NotImplementedException();
                    }

                    foreach (var item in items)
                    {
                        mi.Invoke(current, new object[] {
                            item
                        });
                    }
                }
            }