Esempio n. 1
0
        public bool TryCreate(IDictionary <string, object> data, out object result)
        {
            bool   anyPropertiesSet = false;
            object obj = Activator.CreateInstance(_concreteType);
            object value;

            foreach (var propertyInfo in _concreteType.GetProperties().Where(pi => CanSetProperty(pi, data)))
            {
                value = data[propertyInfo.Name];

                if (ConcreteCollectionTypeCreator.IsCollectionType(propertyInfo.PropertyType))
                {
                    if (!ConcreteCollectionTypeCreator.TryCreate(propertyInfo.PropertyType, (IEnumerable)value, out value))
                    {
                        continue;
                    }
                }
                else
                {
                    var subData = value as IDictionary <string, object>;
                    if (subData != null && !ConcreteTypeCreator.Get(propertyInfo.PropertyType).TryCreate(subData, out value))
                    {
                        continue;
                    }
                }

                propertyInfo.SetValue(obj, value, null);
                anyPropertiesSet = true;
            }

            result = anyPropertiesSet ? obj : null;

            return(anyPropertiesSet);
        }
Esempio n. 2
0
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            if (ConcreteCollectionTypeCreator.IsCollectionType(binder.Type))
            {
                if (ConcreteCollectionTypeCreator.TryCreate(binder.Type, this, out result))
                {
                    return(true);
                }
            }

            return(base.TryConvert(binder, out result));
        }
Esempio n. 3
0
        public override bool TryConvert(ConvertBinder binder, out object result)
        {
            if (binder.Type == typeof(IEnumerable <object>))
            {
                result = Cast <object>();
                return(true);
            }

            if (ConcreteCollectionTypeCreator.IsCollectionType(binder.Type))
            {
                if (ConcreteCollectionTypeCreator.TryCreate(binder.Type, this, out result))
                {
                    return(true);
                }
            }

            return(base.TryConvert(binder, out result));
        }