Ejemplo n.º 1
0
        /// <summary>
        /// Processes properties for linked dropdowns.
        /// </summary>
        /// <param name="modelPropertyInfos">The model property infos.</param>
        private static void ProcessDropDowns(List <ModelPropertyInfo> modelPropertyInfos)
        {
            var currentProperties = modelPropertyInfos.ToArray();

            foreach (var propertyInfo in currentProperties)
            {
                if (propertyInfo.DropDownSource != null)
                {
                    var dropdownSourceProperty =
                        modelPropertyInfos.SingleOrDefault(p => p.Name == propertyInfo.DropDownSource.DropDownPropertyName);
                    if (dropdownSourceProperty != null)
                    {
                        dropdownSourceProperty.DropDownForProperty = propertyInfo;

                        if (dropdownSourceProperty.PropertyInfo.PropertyType.IsGenericType)
                        {
                            var dropdownType = dropdownSourceProperty.PropertyInfo.PropertyType.GetGenericArguments().First();

                            //Get the display field from the type's custom attributes
                            var displayAttribute = ModelReflectionHelper.GetDisplayColumnAttribute(dropdownType.GetCustomAttributes(inherit: true));
                            if (displayAttribute != null)
                            {
                                dropdownSourceProperty.DisplayField = displayAttribute.DisplayColumn;
                            }

                            //Get the value field from the property marked as key
                            dropdownSourceProperty.ValueField = ModelReflectionHelper.GetKeyFieldName(dropdownType);
                        }

                        propertyInfo.DropDownSourceProperty = dropdownSourceProperty;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the ModelPropertyInfo collection for all the properties of a Model.
        /// </summary>
        /// <param name="targetType">The Model target type.</param>
        /// <returns></returns>
        private static List <ModelPropertyInfo> GetModelProperties(Type targetType)
        {
            var modelPropertyInfos = new List <ModelPropertyInfo>();
            var properties         = targetType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

            foreach (var property in properties)
            {
                var attributes        = property.GetCustomAttributes(false);
                var modelPropertyInfo = new ModelPropertyInfo
                {
                    Name           = property.Name,
                    PropertyInfo   = property,
                    IsRequired     = (property.PropertyType == typeof(Int32)) || ModelReflectionHelper.CheckHasRequiredAttribute(attributes),
                    Length         = ModelReflectionHelper.GetLenghtAttribute(attributes),
                    ExtXType       = ModelReflectionHelper.GetExtXType(property, attributes),
                    Label          = ModelReflectionHelper.GetLabel(attributes) ?? property.Name,
                    DropDownSource = ModelReflectionHelper.GetDropDownAttribute(attributes),
                    Mapping        = ModelReflectionHelper.GetMappingAttribute(attributes)
                };

                modelPropertyInfos.Add(modelPropertyInfo);
            }

            ModelReflector.ProcessDropDowns(modelPropertyInfos);

            return(modelPropertyInfos);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the ExtJS XType for the property from it's custom attributes.
        /// </summary>
        /// <param name="propertyInfo">The model property's type.</param>
        /// <param name="attributes">The collection of custom attributes.</param>
        /// <returns></returns>
        public static string GetExtXType(PropertyInfo propertyInfo, object[] attributes)
        {
            if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>))
            {
                return(ExtJsXTypes.combo.ToString());
            }

            var dropdownAttribute = ModelReflectionHelper.GetDropDownAttribute(attributes);

            if (dropdownAttribute != null)
            {
                return(ExtJsXTypes.combo.ToString());
            }

            return(ExtJsXTypes.textfield.ToString());
        }