/// <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); }
/// <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()); }