Exemplo n.º 1
0
        private void ProcessViewModel(IViewModel viewModel, Type type)
        {
            //PropertyInfo[] props = type.GetProperties();
            var props = resolver.GetModelProperties(type);
            IPropertyAttribute propAttribute;
            object             propertyValue = null;

            foreach (var prop in props)
            {
                propAttribute = prop.PropertyAttribute;                                            //prop.GetCustomAttributes(typeof(FieldAttributeBase), true).FirstOrDefault() as FieldAttributeBase;
                if (propAttribute != null)                                                         //It has a FieldAttribute
                {
                    var values = propAttribute.GetPropertyValues(viewModel.ModelData, prop, this); //delegate work to the Property Attribute object itself. Allows for custom attribute types to easily be added
                    if (values != null)
                    {
                        try
                        {
                            propertyValue = GetPropertyValue(prop, values);
                            prop.Set(viewModel, propertyValue);
                        }
                        catch (Exception e)
                        {
                            if (e is TargetException || e is InvalidCastException)
                            {
                                throw new PropertyTypeMismatchException(prop, propAttribute, propertyValue);
                            }
                            else
                            {
                                throw e;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessViewModel(IViewModel viewModel, Type type, IContextModel contextModel)
        {
            //PropertyInfo[] props = type.GetProperties();
            var props = _resolver.GetModelProperties(type);
            IPropertyAttribute propAttribute;
            object             propertyValue = null;

            foreach (var prop in props)
            {
                propAttribute = prop.PropertyAttribute; //prop.GetCustomAttributes(typeof(FieldAttributeBase), true).FirstOrDefault() as FieldAttributeBase;
                if (propAttribute != null)              // this property is an IPropertyAttribute
                {
                    IEnumerable values;
                    //ILinkablePropertyAttribute is implemented, we have to pass context data to property.
                    if (propAttribute is ILinkablePropertyAttribute)
                    {
                        values = ((ILinkablePropertyAttribute)propAttribute).GetPropertyValues(viewModel.ModelData, prop, this, contextModel); //delegate work to the Property Attribute object itself. Allows for custom attribute types to easily be added
                    }
                    else
                    {
                        values = propAttribute.GetPropertyValues(viewModel.ModelData, prop, this); //delegate work to the Property Attribute object itself. Allows for custom attribute types to easily be added
                    }
                    if (values != null)
                    {
                        try
                        {
                            propertyValue = GetPropertyValue(prop, values);
                            prop.Set(viewModel, propertyValue);
                        }
                        catch (Exception e)
                        {
                            if (e is TargetException || e is InvalidCastException)
                            {
                                throw new PropertyTypeMismatchException(prop, propAttribute, propertyValue);
                            }
                            else
                            {
                                throw e;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private IModelProperty GetModelProperty(Type type, PropertyInfo property)
        {
            var props = resolver.GetModelProperties(type);

            return(props.FirstOrDefault(x => x.Name == property.Name));
        }