/// <summary> /// Adds local text translations defined implicitly by Description attributes in /// enumeration classes. Only enum values that has Description attribute are added as /// local text. By default, enums are registered in format: /// "Enums.{EnumerationTypeFullName}.{EnumValueName}". EnumerationTypeFullName, is /// fullname of the enumeration type. This can be overridden by attaching a EnumKey /// attribute. /// </summary> /// <param name="typeSource">Type source to search for enumeration classes in</param> /// <param name="languageID">Language ID texts will be added (default is invariant language)</param> /// <param name="registry">Registry</param> public static void AddEnumTexts(this ILocalTextRegistry registry, ITypeSource typeSource, string languageID = LocalText.InvariantLanguageID) { if (typeSource == null) { throw new ArgumentNullException("assemblies"); } var provider = registry ?? throw new ArgumentNullException(nameof(registry)); foreach (var type in typeSource.GetTypes()) { if (type.IsEnum) { var enumKey = EnumMapper.GetEnumTypeKey(type); foreach (var name in Enum.GetNames(type)) { var member = type.GetMember(name); if (member.Length == 0) { continue; } var descAttr = member[0].GetCustomAttribute <DescriptionAttribute>(); if (descAttr != null) { provider.Add(languageID, "Enums." + enumKey + "." + name, descAttr.Description); } } } } }
private void GenerateEnum(Type enumType) { var enumKey = EnumMapper.GetEnumTypeKey(enumType); cw.Indented("[EnumKey(\""); sb.Append(enumKey); sb.AppendLine("\"), PreserveMemberCase]"); cw.Indented("public enum "); sb.AppendLine(enumType.Name); cw.InBrace(delegate { var names = Enum.GetNames(enumType); var values = Enum.GetValues(enumType); int i = 0; foreach (var name in names) { if (i > 0) { sb.AppendLine(","); } cw.Indented(name); sb.Append(" = "); sb.Append(Convert.ToInt32(((IList)values)[i])); i++; } sb.AppendLine(); }); }
private void GenerateEnum(Type enumType) { var codeNamespace = GetNamespace(enumType); var enumKey = EnumMapper.GetEnumTypeKey(enumType); cw.Indented("export enum "); var identifier = MakeFriendlyName(enumType, codeNamespace); var fullName = (codeNamespace.IsEmptyOrNull() ? "" : codeNamespace + ".") + identifier; generatedTypes.Add(fullName); cw.InBrace(delegate { var names = Enum.GetNames(enumType); var values = (IList)Enum.GetValues(enumType); var inserted = 0; for (var i = 0; i < names.Length; i++) { var name = names[i]; var member = enumType.GetMember(name); if (member != null && member.Length > 0 && member[0].GetAttribute <IgnoreAttribute>(false) != null) { continue; } if (inserted > 0) { sb.AppendLine(","); } cw.Indented(name); sb.Append(" = "); sb.Append(Convert.ToInt32(values[i])); inserted++; } sb.AppendLine(); }); cw.Indented("Serenity.Decorators.registerEnumType("); sb.Append(enumType.Name); sb.Append(", '"); sb.Append(fullName); sb.Append("'"); if (enumKey != fullName) { sb.Append(", '"); sb.Append(enumKey); sb.AppendLine("');"); } else { sb.AppendLine(");"); } }
private void GenerateEnum(Type enumType) { var codeNamespace = GetNamespace(enumType); var enumKey = EnumMapper.GetEnumTypeKey(enumType); cw.Indented("[EnumKey(\""); sb.Append(enumKey); sb.AppendLine("\"), PreserveMemberCase]"); cw.Indented("public enum "); sb.AppendLine(enumType.Name); cw.InBrace(delegate { var names = Enum.GetNames(enumType); var values = (IList)Enum.GetValues(enumType); var inserted = 0; for (var i = 0; i < names.Length; i++) { var name = names[i]; var member = enumType.GetMember(name); if (member != null && member.Length > 0 && member[0].GetAttribute <IgnoreAttribute>(false) != null) { continue; } if (inserted > 0) { sb.AppendLine(","); } cw.Indented(name); sb.Append(" = "); sb.Append(Convert.ToInt32(values[i])); inserted++; } sb.AppendLine(); }); }
private static void SetFormatting(IPropertySource source, PropertyItem item) { var formatterTypeAttr = source.GetAttribute <FormatterTypeAttribute>(); var enumType = source.EnumType; var valueType = source.ValueType; var basedOnField = source.BasedOnField; if (formatterTypeAttr == null) { if (enumType != null) { item.FormatterType = "Enum"; item.FormatterParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } else if (valueType == typeof(DateTime) || valueType == typeof(DateTime?)) { if (basedOnField is object && basedOnField is DateTimeField dtf && !dtf.DateOnly) { item.FormatterType = "DateTime"; } else { item.FormatterType = "Date"; } } else if (valueType == typeof(bool)) { item.FormatterType = "Checkbox"; } else if (valueType == typeof(decimal) || valueType == typeof(double) || valueType == typeof(float) || valueType == typeof(int)) { item.FormatterType = "Number"; } }
public static void Initialize(IEnumerable <Assembly> assemblies, string languageID = LocalText.InvariantLanguageID, ILocalTextRegistry registry = null) #endif { assemblies = assemblies ?? ExtensibilityHelper.SelfAssemblies; if (assemblies == null) { throw new ArgumentNullException("assemblies"); } var provider = registry ?? Dependency.Resolve <ILocalTextRegistry>(); foreach (var assembly in assemblies) { foreach (var type in assembly.GetTypes()) { if (type.IsEnum) { var enumKey = EnumMapper.GetEnumTypeKey(type); foreach (var name in Enum.GetNames(type)) { var member = type.GetMember(name); if (member.Length == 0) { continue; } var descAttr = member[0].GetCustomAttribute <DescriptionAttribute>(); if (descAttr != null) { provider.Add(languageID, "Enums." + enumKey + "." + name, descAttr.Description); } } } } } }
private void GenerateEnum(Type enumType) { var codeNamespace = GetNamespace(enumType); var enumKey = EnumMapper.GetEnumTypeKey(enumType); cw.Indented("export enum "); var identifier = MakeFriendlyName(enumType, codeNamespace); generatedTypes.Add((codeNamespace.IsEmptyOrNull() ? "" : codeNamespace + ".") + identifier); cw.InBrace(delegate { var names = Enum.GetNames(enumType); var values = Enum.GetValues(enumType); int i = 0; foreach (var name in names) { if (i > 0) { sb.AppendLine(","); } cw.Indented(name); sb.Append(" = "); sb.Append(Convert.ToInt32(((IList)values)[i])); i++; } sb.AppendLine(); }); cw.Indented("Serenity.Decorators.registerEnum("); sb.Append(enumType.Name); sb.Append(", '"); sb.Append(enumKey); sb.AppendLine("');"); }
private void SetEditing(IPropertySource source, PropertyItem item) { var editorTypeAttr = source.GetAttribute <EditorTypeAttribute>(); if (editorTypeAttr == null) { item.EditorType = AutoDetermineEditorType(source.ValueType, source.EnumType); } else { item.EditorType = editorTypeAttr.EditorType; editorTypeAttr.SetParams(item.EditorParams); } if (source.EnumType != null) { item.EditorParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } if (!ReferenceEquals(null, source.BasedOnField)) { if (item.EditorType == "Decimal" && (source.BasedOnField is DoubleField || source.BasedOnField is DecimalField) && source.BasedOnField.Size > 0 && source.BasedOnField.Scale < source.BasedOnField.Size) { string minVal = new String('0', source.BasedOnField.Size - source.BasedOnField.Scale); if (source.BasedOnField.Scale > 0) { minVal += "." + new String('0', source.BasedOnField.Scale); } string maxVal = minVal.Replace('0', '9'); item.EditorParams["minValue"] = minVal; item.EditorParams["maxValue"] = maxVal; } else if (source.BasedOnField.Size > 0) { item.EditorParams["maxLength"] = source.BasedOnField.Size; item.MaxLength = source.BasedOnField.Size; } } var maxLengthAttr = source.GetAttribute <MaxLengthAttribute>(); if (maxLengthAttr != null) { item.MaxLength = maxLengthAttr.MaxLength; item.EditorParams["maxLength"] = maxLengthAttr.MaxLength; } foreach (EditorOptionAttribute param in source.GetAttributes <EditorOptionAttribute>()) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.EditorParams[key] = param.Value; } }
private void SetEditing(IPropertySource source, PropertyItem item) { var editorTypeAttr = source.GetAttribute <EditorTypeAttribute>(); if (editorTypeAttr == null) { item.EditorType = AutoDetermineEditorType(source.ValueType, source.EnumType, item.EditorParams); } else { item.EditorType = editorTypeAttr.EditorType; editorTypeAttr.SetParams(item.EditorParams); if (item.EditorType == "Lookup" && !item.EditorParams.ContainsKey("lookupKey")) { var distinct = source.GetAttribute <DistinctValuesEditorAttribute>(); if (distinct != null) { string prefix = null; if (distinct.RowType != null) { if (!distinct.RowType.IsInterface && !distinct.RowType.IsAbstract && distinct.RowType.IsSubclassOf(typeof(Row))) { prefix = ((Row)Activator.CreateInstance(distinct.RowType)) .GetFields().LocalTextPrefix; } } else { var isRow = source.Property != null && source.Property.ReflectedType != null && !source.Property.ReflectedType.IsAbstract && source.Property.ReflectedType.IsSubclassOf(typeof(Row)); if (!isRow) { if (!ReferenceEquals(null, source.BasedOnField)) { prefix = source.BasedOnField.Fields.LocalTextPrefix; } } else { prefix = ((Row)Activator.CreateInstance(source.Property.ReflectedType)) .GetFields().LocalTextPrefix; } } if (prefix != null) { var propertyName = distinct.PropertyName.IsEmptyOrNull() ? (!ReferenceEquals(null, source.BasedOnField) ? (source.BasedOnField.PropertyName ?? source.BasedOnField.Name) : item.Name) : distinct.PropertyName; if (!string.IsNullOrEmpty(propertyName)) { item.EditorParams["lookupKey"] = "Distinct." + prefix + "." + propertyName; } } } } } if (source.EnumType != null) { item.EditorParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } var dtka = source.GetAttribute <DateTimeKindAttribute>(); if (dtka != null && dtka.Value != DateTimeKind.Unspecified) { item.EditorParams["useUtc"] = true; } if (!ReferenceEquals(null, source.BasedOnField)) { if (dtka == null && source.BasedOnField is DateTimeField && ((DateTimeField)source.BasedOnField).DateTimeKind != DateTimeKind.Unspecified) { item.EditorParams["useUtc"] = true; } if (item.EditorType == "Decimal" && (source.BasedOnField is DoubleField || source.BasedOnField is SingleField || source.BasedOnField is DecimalField) && source.BasedOnField.Size > 0 && source.BasedOnField.Scale < source.BasedOnField.Size && !item.EditorParams.ContainsKey("minValue") && !item.EditorParams.ContainsKey("maxValue")) { string minVal = new String('0', source.BasedOnField.Size - source.BasedOnField.Scale); if (source.BasedOnField.Scale > 0) { minVal += "." + new String('0', source.BasedOnField.Scale); } string maxVal = minVal.Replace('0', '9'); if ((item.EditorParams.ContainsKey("allowNegatives") && Convert.ToBoolean(item.EditorParams["allowNegatives"] ?? false) == true) || (!item.EditorParams.ContainsKey("allowNegatives") && DecimalEditorAttribute.AllowNegativesByDefault)) { minVal = "-" + maxVal; } item.EditorParams["minValue"] = minVal; item.EditorParams["maxValue"] = maxVal; } else if (item.EditorType == "Integer" && (source.BasedOnField is Int32Field || source.BasedOnField is Int16Field || source.BasedOnField is Int64Field) && !item.EditorParams.ContainsKey("minValue") && !item.EditorParams.ContainsKey("maxValue")) { item.EditorParams["maxValue"] = source.BasedOnField is Int16Field ? Int16.MaxValue : source.BasedOnField is Int32Field ? Int32.MaxValue : source.BasedOnField is Int64Field ? Int64.MaxValue : (object)null; if ((item.EditorParams.ContainsKey("allowNegatives") && Convert.ToBoolean(item.EditorParams["allowNegatives"] ?? false) == true) || (!item.EditorParams.ContainsKey("allowNegatives") && DecimalEditorAttribute.AllowNegativesByDefault) && item.EditorParams["maxValue"] != null) { item.EditorParams["minValue"] = -Convert.ToInt64(item.EditorParams["maxValue"]) - 1; } } else if (source.BasedOnField.Size > 0) { item.EditorParams["maxLength"] = source.BasedOnField.Size; item.MaxLength = source.BasedOnField.Size; } } var maxLengthAttr = source.GetAttribute <MaxLengthAttribute>(); if (maxLengthAttr != null) { item.MaxLength = maxLengthAttr.MaxLength; item.EditorParams["maxLength"] = maxLengthAttr.MaxLength; } foreach (EditorOptionAttribute param in source.GetAttributes <EditorOptionAttribute>()) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.EditorParams[key] = param.Value; } SetServiceLookupParams(editorTypeAttr, item.EditorParams); }
private static void HandleFormatter(MemberInfo member, Type valueType, Type enumType, Field basedOnField, PropertyItem pi) { var formatterTypeAttr = (FormatterTypeAttribute)GetAttribute(member, basedOnField, typeof(FormatterTypeAttribute)); if (formatterTypeAttr == null) { if (enumType != null) { pi.FormatterType = "Enum"; pi.FormatterParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } else if (valueType == typeof(DateTime) || valueType == typeof(DateTime?)) { if (!ReferenceEquals(null, basedOnField) && basedOnField is DateTimeField) { switch (((DateTimeField)basedOnField).DateTimeKind) { case DateTimeKind.Unspecified: pi.FormatterType = "Date"; break; default: pi.FormatterType = "DateTime"; break; } } else { pi.FormatterType = "Date"; } } else if (valueType == typeof(Boolean)) { pi.FormatterType = "Checkbox"; } else if (valueType == typeof(Decimal) || valueType == typeof(Double) || valueType == typeof(Int32)) { pi.FormatterType = "Number"; } } else { pi.FormatterType = formatterTypeAttr.FormatterType; formatterTypeAttr.SetParams(pi.FormatterParams); } var displayFormatAttr = (DisplayFormatAttribute)GetAttribute(member, basedOnField, typeof(DisplayFormatAttribute)); if (displayFormatAttr != null) { pi.DisplayFormat = displayFormatAttr.Value; pi.FormatterParams["displayFormat"] = displayFormatAttr.Value; } foreach (FormatterOptionAttribute param in GetAttributes(member, basedOnField, typeof(FormatterOptionAttribute))) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } pi.FormatterParams[key] = param.Value; } }
public static PropertyItem GetCustomFieldPropertyItem(ICustomFieldDefinition definition, Field basedOnField) { PropertyItem pi = new PropertyItem(); pi.Name = !ReferenceEquals(null, basedOnField) ? (basedOnField.PropertyName ?? basedOnField.Name) : definition.Name; pi.Category = definition.Category.TrimToNull(); pi.ReadOnly = false; pi.Title = !ReferenceEquals(null, basedOnField) ? basedOnField.Title : definition.Title; pi.DefaultValue = definition.DefaultValue; pi.Insertable = ReferenceEquals(null, basedOnField) || ((basedOnField.Flags & FieldFlags.Insertable) == FieldFlags.Insertable); pi.Updatable = ReferenceEquals(null, basedOnField) || ((basedOnField.Flags & FieldFlags.Updatable) == FieldFlags.Updatable); pi.Localizable = definition.IsLocalizable; Type enumType = null; if (!ReferenceEquals(null, basedOnField) && basedOnField is IEnumTypeField) { enumType = (basedOnField as IEnumTypeField).EnumType; if (enumType != null && !enumType.IsEnum) { enumType = null; } } if (!definition.EditorType.IsTrimmedEmpty()) { pi.EditorType = definition.EditorType.TrimToNull(); } else { if (enumType != null) { pi.EditorType = "Enum"; } else if (definition.FieldType == CustomFieldType.Date || definition.FieldType == CustomFieldType.DateTime) { pi.EditorType = "Date"; } else if (definition.FieldType == CustomFieldType.Boolean) { pi.EditorType = "Boolean"; } else if (definition.FieldType == CustomFieldType.Decimal) { pi.EditorType = "Decimal"; } else if (definition.FieldType == CustomFieldType.Int32 || definition.FieldType == CustomFieldType.Int64) { pi.EditorType = "Integer"; } else { pi.EditorType = "String"; } } if (enumType != null) { pi.EditorParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } if (!ReferenceEquals(null, basedOnField)) { if (basedOnField is StringField && basedOnField.Size > 0) { pi.EditorParams["maxLength"] = basedOnField.Size; pi.MaxLength = basedOnField.Size; } if ((basedOnField.Flags & FieldFlags.NotNull) == FieldFlags.NotNull) { pi.Required = true; } } if (definition.IsRequired) { pi.Required = true; } if (definition.Size != 0 && definition.FieldType == CustomFieldType.String) { pi.MaxLength = definition.Size; pi.EditorParams["maxLength"] = definition.Size; } var editorOptionsJson = definition.EditorOptions.TrimToNull(); if (editorOptionsJson != null && editorOptionsJson.StartsWith("{")) { var editorOptions = JsonConvert.DeserializeObject <Dictionary <string, object> >(editorOptionsJson, JsonSettings.Tolerant); foreach (var option in editorOptions) { pi.EditorParams[option.Key] = option.Value; } } return(pi); }
public static List <PropertyItem> GetPropertyItemsFor(Type type) { if (type == null) { throw new ArgumentNullException("type"); } var list = new List <PropertyItem>(); var basedOnRow = GetBasedOnRow(type); var localizationRowHandler = GetLocalizationRowHandler(basedOnRow); foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance)) { PropertyItem pi = new PropertyItem(); if (member.MemberType != MemberTypes.Property && member.MemberType != MemberTypes.Field) { continue; } var hiddenAttribute = member.GetCustomAttributes(typeof(IgnoreAttribute), false); if (hiddenAttribute.Length > 0) { continue; } var memberType = member.MemberType == MemberTypes.Property ? ((PropertyInfo)member).PropertyType : ((FieldInfo)member).FieldType; var nullableType = Nullable.GetUnderlyingType(memberType); var valueType = nullableType ?? memberType; pi.Name = member.Name; Field basedOnField = null; if (basedOnRow != null) { basedOnField = basedOnRow.FindField(member.Name); if (ReferenceEquals(null, basedOnField)) { basedOnField = basedOnRow.FindFieldByPropertyName(member.Name); } } Func <Type, Attribute> getAttribute = attrType => GetAttribute(member, basedOnField, attrType); Func <Type, IEnumerable <Attribute> > getAttributes = attrType => GetAttributes(member, basedOnField, attrType); var displayNameAttribute = (DisplayNameAttribute)member.GetCustomAttribute(typeof(DisplayNameAttribute), false); if (displayNameAttribute != null) { pi.Title = displayNameAttribute.DisplayName; } var hintAttribute = (HintAttribute)getAttribute(typeof(HintAttribute)); if (hintAttribute != null) { pi.Hint = hintAttribute.Hint; } var placeholderAttribute = (PlaceholderAttribute)getAttribute(typeof(PlaceholderAttribute)); if (placeholderAttribute != null) { pi.Placeholder = placeholderAttribute.Value; } var categoryAttribute = (CategoryAttribute)getAttribute(typeof(CategoryAttribute)); if (categoryAttribute != null) { pi.Category = categoryAttribute.Category; } else if (list.Count > 0) { pi.Category = list[list.Count - 1].Category; } var cssClassAttr = (CssClassAttribute)getAttribute(typeof(CssClassAttribute)); if (cssClassAttr != null) { pi.CssClass = cssClassAttr.CssClass; } var alignmentAttr = (AlignmentAttribute)getAttribute(typeof(AlignmentAttribute)); if (alignmentAttr != null) { pi.Alignment = alignmentAttr.Value; } var sortOrderAttr = (SortOrderAttribute)getAttribute(typeof(SortOrderAttribute)); if (sortOrderAttr != null && sortOrderAttr.SortOrder != 0) { pi.SortOrder = sortOrderAttr.SortOrder; } if (getAttribute(typeof(OneWayAttribute)) != null) { pi.OneWay = true; } if (getAttribute(typeof(ReadOnlyAttribute)) != null) { pi.ReadOnly = true; } var resizableAttr = (ResizableAttribute)getAttribute(typeof(ResizableAttribute)); pi.Resizable = resizableAttr == null || resizableAttr.Value; var widthAttr = (WidthAttribute)getAttribute(typeof(WidthAttribute)); pi.Width = widthAttr == null ? (!ReferenceEquals(null, basedOnField) ? AutoWidth(basedOnField) : 80) : widthAttr.Value; pi.MinWidth = widthAttr == null ? 0 : widthAttr.Min; pi.MaxWidth = widthAttr == null ? 0 : widthAttr.Max; var editLinkAttr = (EditLinkAttribute)getAttribute(typeof(EditLinkAttribute)); pi.EditLink = editLinkAttr != null && editLinkAttr.Value; pi.EditLinkItemType = editLinkAttr != null ? editLinkAttr.ItemType : (string)null; pi.EditLinkIdField = editLinkAttr != null ? editLinkAttr.IdField : null; pi.EditLinkCssClass = editLinkAttr != null ? editLinkAttr.CssClass : null; if (pi.EditLinkItemType != null && pi.EditLinkIdField == null) { pi.EditLinkIdField = AutoDetermineIdField(basedOnField); } if (pi.Title == null) { if (!ReferenceEquals(null, basedOnField)) { Field textualField = null; if (basedOnField.TextualField != null) { textualField = basedOnField.Fields.FindFieldByPropertyName(basedOnField.TextualField) ?? basedOnField.Fields.FindField(basedOnField.TextualField); } if (!ReferenceEquals(null, textualField)) { pi.Title = !object.ReferenceEquals(null, textualField.Caption) ? textualField.Caption.Key : textualField.Title; } else { pi.Title = !object.ReferenceEquals(null, basedOnField.Caption) ? basedOnField.Caption.Key : basedOnField.Title; } } else { pi.Title = pi.Name; } } var defaultValueAttribute = (DefaultValueAttribute)member.GetCustomAttribute(typeof(DefaultValueAttribute), false); if (defaultValueAttribute != null) { pi.DefaultValue = defaultValueAttribute.Value; } else if (!ReferenceEquals(null, basedOnField) && basedOnField.DefaultValue != null) { pi.DefaultValue = basedOnField.DefaultValue; } var insertableAttribute = member.GetCustomAttribute <InsertableAttribute>(); if (insertableAttribute != null) { pi.Insertable = insertableAttribute.Value; } else if (!ReferenceEquals(null, basedOnField)) { pi.Insertable = (basedOnField.Flags & FieldFlags.Insertable) == FieldFlags.Insertable; } else { pi.Insertable = true; } var updatableAttribute = member.GetCustomAttribute <UpdatableAttribute>(); if (updatableAttribute != null) { pi.Updatable = updatableAttribute.Value; } else if (!ReferenceEquals(null, basedOnField)) { pi.Updatable = (basedOnField.Flags & FieldFlags.Updatable) == FieldFlags.Updatable; } else { pi.Updatable = true; } pi.Localizable = getAttribute(typeof(LocalizableAttribute)) != null || (!ReferenceEquals(null, basedOnField) && localizationRowHandler != null && localizationRowHandler.IsLocalized(basedOnField)); var visibleAttribute = (VisibleAttribute)getAttribute(typeof(VisibleAttribute)); if (visibleAttribute != null && visibleAttribute.Value == false) { pi.Visible = false; } var enumType = GetEnumType(valueType, basedOnField); var editorTypeAttr = (EditorTypeAttribute)getAttribute(typeof(EditorTypeAttribute)); if (editorTypeAttr == null) { pi.EditorType = AutoDetermineEditorType(valueType, enumType); } else { pi.EditorType = editorTypeAttr.EditorType; editorTypeAttr.SetParams(pi.EditorParams); } if (enumType != null) { pi.EditorParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } if (!ReferenceEquals(null, basedOnField)) { if (pi.EditorType == "Decimal" && (basedOnField is DoubleField || basedOnField is DecimalField) && basedOnField.Size > 0 && basedOnField.Scale < basedOnField.Size) { string minVal = new String('0', basedOnField.Size - basedOnField.Scale); if (basedOnField.Scale > 0) { minVal += "." + new String('0', basedOnField.Scale); } string maxVal = minVal.Replace('0', '9'); pi.EditorParams["minValue"] = minVal; pi.EditorParams["maxValue"] = maxVal; } else if (basedOnField.Size > 0) { pi.EditorParams["maxLength"] = basedOnField.Size; pi.MaxLength = basedOnField.Size; } if ((basedOnField.Flags & FieldFlags.NotNull) == FieldFlags.NotNull) { pi.Required = true; } } var reqAttr = (RequiredAttribute)getAttribute(typeof(RequiredAttribute)); if (reqAttr != null && (pi.Required != null || reqAttr.IsRequired)) { pi.Required = reqAttr.IsRequired; } var maxLengthAttr = (MaxLengthAttribute)getAttribute(typeof(MaxLengthAttribute)); if (maxLengthAttr != null) { pi.MaxLength = maxLengthAttr.MaxLength; pi.EditorParams["maxLength"] = maxLengthAttr.MaxLength; } foreach (EditorOptionAttribute param in getAttributes(typeof(EditorOptionAttribute))) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } pi.EditorParams[key] = param.Value; } HandleFormatter(member, valueType, enumType, basedOnField, pi); HandleFiltering(member, valueType, enumType, basedOnField, pi); list.Add(pi); } return(list); }
private static void HandleFiltering(MemberInfo member, Type valueType, Type enumType, Field basedOnField, PropertyItem pi) { var filterOnlyAttr = GetAttribute(member, basedOnField, typeof(FilterOnlyAttribute)) as FilterOnlyAttribute; var notFilterableAttr = GetAttribute(member, basedOnField, typeof(NotFilterableAttribute)) as NotFilterableAttribute; if (filterOnlyAttr != null && filterOnlyAttr.Value) { pi.FilterOnly = true; } if (notFilterableAttr != null && notFilterableAttr.Value) { pi.NotFilterable = true; } if (pi.NotFilterable == true) { return; } string idFieldName = AutoDetermineIdField(basedOnField); Field idField = null; if (idFieldName != null) { idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); if (Object.ReferenceEquals(idField, null) || (idField.TextualField != basedOnField.PropertyName && idField.TextualField != basedOnField.Name)) { idField = null; idFieldName = null; } } var filteringTypeAttr = (FilteringTypeAttribute)GetAttribute(member, basedOnField, typeof(FilteringTypeAttribute)) ?? (FilteringTypeAttribute)GetAttribute(null, idField, typeof(FilteringTypeAttribute)); if (filteringTypeAttr == null) { var editorAttr = (EditorTypeAttribute)GetAttribute(member, basedOnField, typeof(EditorTypeAttribute)) ?? (EditorTypeAttribute)GetAttribute(null, idField, typeof(EditorTypeAttribute)); if (idFieldName != null) { pi.FilteringParams["idField"] = idFieldName; pi.FilteringIdField = idFieldName; } if (editorAttr != null && !standardFilteringEditors.Contains(editorAttr.EditorType)) { if (editorAttr is LookupEditorAttribute || editorAttr is AsyncLookupEditorAttribute) { var async = editorAttr as AsyncLookupEditorAttribute; pi.FilteringType = async != null ? "AsyncLookup" : "Lookup"; pi.FilteringParams["lookupKey"] = async != null ? async.LookupKey : ((LookupEditorAttribute)editorAttr).LookupKey; } else { pi.FilteringType = "Editor"; pi.FilteringParams["editorType"] = editorAttr.EditorType; pi.FilteringParams["useLike"] = valueType == typeof(String); } } else if (enumType != null) { pi.FilteringType = "Enum"; pi.FilteringParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } else if (valueType == typeof(DateTime)) { if (!ReferenceEquals(null, basedOnField) && basedOnField is DateTimeField) { switch (((DateTimeField)basedOnField).DateTimeKind) { case DateTimeKind.Unspecified: pi.FilteringType = "Date"; break; default: pi.FilteringType = "DateTime"; break; } } else { pi.FilteringType = "Date"; } } else if (valueType == typeof(Boolean)) { pi.FilteringType = "Boolean"; } else if (valueType == typeof(Decimal) || valueType == typeof(Double)) { pi.FilteringType = "Decimal"; } else if (valueType == typeof(Int32) || valueType == typeof(Int16) || valueType == typeof(Int64)) { pi.FilteringType = "Integer"; } else { pi.FilteringType = "String"; } } else { pi.FilteringType = filteringTypeAttr.FilteringType; filteringTypeAttr.SetParams(pi.FilteringParams); if (pi.FilteringType == "Editor") { if (!pi.FilteringParams.ContainsKey("editorType")) { var editorAttr = (EditorTypeAttribute)GetAttribute(member, basedOnField, typeof(EditorTypeAttribute)) ?? (EditorTypeAttribute)GetAttribute(member, idField, typeof(EditorTypeAttribute)); if (editorAttr != null) { pi.FilteringParams["editorType"] = editorAttr.EditorType; } } if (!pi.FilteringParams.ContainsKey("useLike")) { if (valueType == typeof(String)) { pi.FilteringParams["useLike"] = true; } } } object idFieldObj; if (pi.FilteringParams.TryGetValue("idField", out idFieldObj) && idFieldObj is string) { pi.FilteringIdField = (idFieldObj as string).TrimToNull(); } else { pi.FilteringIdField = idFieldName; } } var displayFormatAttr = (DisplayFormatAttribute)GetAttribute(member, basedOnField, typeof(DisplayFormatAttribute)); if (displayFormatAttr != null) { pi.FilteringParams["displayFormat"] = displayFormatAttr.Value; } foreach (FilteringOptionAttribute param in GetAttributes(null, idField, typeof(FilteringOptionAttribute)).Concat( GetAttributes(member, basedOnField, typeof(FilteringOptionAttribute)))) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } pi.FilteringParams[key] = param.Value; } }
private void SetEditing(IPropertySource source, PropertyItem item) { var editorTypeAttr = source.GetAttribute <EditorTypeAttribute>(); if (editorTypeAttr == null) { item.EditorType = AutoDetermineEditorType(source.ValueType, source.EnumType, item.EditorParams); } else { item.EditorType = editorTypeAttr.EditorType; editorTypeAttr.SetParams(item.EditorParams); if (item.EditorType == "Lookup" && !item.EditorParams.ContainsKey("lookupKey")) { var distinct = source.GetAttribute <DistinctValuesEditorAttribute>(); if (distinct != null) { string prefix = null; if (distinct.RowType != null) { if (!distinct.RowType.IsInterface && !distinct.RowType.IsAbstract && distinct.RowType.IsSubclassOf(typeof(Row))) { prefix = ((Row)Activator.CreateInstance(distinct.RowType)) .GetFields().LocalTextPrefix; } } else { var isRow = source.Property != null && source.Property.ReflectedType != null && !source.Property.ReflectedType.IsAbstract && source.Property.ReflectedType.IsSubclassOf(typeof(Row)); if (!isRow) { if (!ReferenceEquals(null, source.BasedOnField)) { prefix = source.BasedOnField.Fields.LocalTextPrefix; } } else { prefix = ((Row)Activator.CreateInstance(source.Property.ReflectedType)) .GetFields().LocalTextPrefix; } } if (prefix != null) { var propertyName = distinct.PropertyName.IsEmptyOrNull() ? (!ReferenceEquals(null, source.BasedOnField) ? (source.BasedOnField.PropertyName ?? source.BasedOnField.Name) : item.Name) : distinct.PropertyName; if (!string.IsNullOrEmpty(propertyName)) { item.EditorParams["lookupKey"] = "Distinct." + prefix + "." + propertyName; } } } } } if (source.EnumType != null) { item.EditorParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } if (!ReferenceEquals(null, source.BasedOnField)) { if (item.EditorType == "Decimal" && (source.BasedOnField is DoubleField || source.BasedOnField is DecimalField) && source.BasedOnField.Size > 0 && source.BasedOnField.Scale < source.BasedOnField.Size && !item.EditorParams.ContainsKey("minValue") && !item.EditorParams.ContainsKey("maxValue")) { string minVal = new String('0', source.BasedOnField.Size - source.BasedOnField.Scale); if (source.BasedOnField.Scale > 0) { minVal += "." + new String('0', source.BasedOnField.Scale); } string maxVal = minVal.Replace('0', '9'); item.EditorParams["minValue"] = minVal; item.EditorParams["maxValue"] = maxVal; } else if (source.BasedOnField.Size > 0) { item.EditorParams["maxLength"] = source.BasedOnField.Size; item.MaxLength = source.BasedOnField.Size; } } var maxLengthAttr = source.GetAttribute <MaxLengthAttribute>(); if (maxLengthAttr != null) { item.MaxLength = maxLengthAttr.MaxLength; item.EditorParams["maxLength"] = maxLengthAttr.MaxLength; } foreach (EditorOptionAttribute param in source.GetAttributes <EditorOptionAttribute>()) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.EditorParams[key] = param.Value; } }
private static void SetFiltering(IPropertySource source, PropertyItem item) { var filterOnlyAttr = source.GetAttribute <FilterOnlyAttribute>(); var notFilterableAttr = source.GetAttribute <NotFilterableAttribute>(); if (filterOnlyAttr != null && filterOnlyAttr.Value) { item.FilterOnly = true; } if (notFilterableAttr != null && notFilterableAttr.Value) { item.NotFilterable = true; } if (item.NotFilterable == true) { return; } var quickFilterAttr = source.GetAttribute <QuickFilterAttribute>(); if (quickFilterAttr != null) { item.QuickFilter = true; if (quickFilterAttr.Separator) { item.QuickFilterSeparator = true; } if (!string.IsNullOrEmpty(quickFilterAttr.CssClass)) { item.QuickFilterCssClass = quickFilterAttr.CssClass; } } var basedOnField = source.BasedOnField; if (basedOnField is object && notFilterableAttr == null) { if (basedOnField.Flags.HasFlag(FieldFlags.DenyFiltering) || basedOnField.Flags.HasFlag(FieldFlags.NotMapped)) { item.NotFilterable = true; } } Field idField; string idFieldName; var filteringIdField = source.GetAttribute <FilteringIdFieldAttribute>(); if (filteringIdField != null) { idFieldName = filteringIdField.Value; idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); } else { idFieldName = AutoDetermineIdField(basedOnField); idField = null; if (idFieldName != null) { idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); if (idField is null || (idField.TextualField != basedOnField.PropertyName && idField.TextualField != basedOnField.Name)) { idField = null; idFieldName = null; } } } var valueType = source.ValueType; var filteringTypeAttr = source.GetAttribute <FilteringTypeAttribute>() ?? idField.GetAttribute <FilteringTypeAttribute>(); if (filteringTypeAttr == null) { var editorAttr = source.GetAttribute <EditorTypeAttribute>() ?? idField.GetAttribute <EditorTypeAttribute>(); void copyParamsFromEditor(string[] keys) { var prm = new Dictionary <string, object>(); editorAttr.SetParams(prm); SetServiceLookupParams(editorAttr, prm); foreach (var key in keys) { if (prm.TryGetValue(key, out object o)) { item.FilteringParams[key] = o; } } } if (idFieldName != null) { item.FilteringParams["idField"] = idFieldName; item.FilteringIdField = idFieldName; } if (editorAttr != null && !standardFilteringEditors.Contains(editorAttr.EditorType)) { if (editorAttr is LookupEditorAttribute) { item.FilteringType = "Lookup"; copyParamsFromEditor(lookupCopyToFilterParams); } else if (editorAttr is ServiceLookupEditorAttribute) { item.FilteringType = "ServiceLookup"; copyParamsFromEditor(serviceLookupCopyToFilterParams); } else { item.FilteringType = "Editor"; item.FilteringParams["editorType"] = editorAttr.EditorType; item.FilteringParams["useLike"] = source.ValueType == typeof(string); if (editorAttr is LookupEditorBaseAttribute leba && leba.Async == true) { item.FilteringParams["async"] = true; } } } else if (source.EnumType != null) { item.FilteringType = "Enum"; item.FilteringParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } else if (valueType == typeof(DateTime)) { if (basedOnField is object && basedOnField is DateTimeField dtf && !dtf.DateOnly) { item.FilteringType = "DateTime"; } else { item.FilteringType = "Date"; } } else if (valueType == typeof(bool)) { item.FilteringType = "Boolean"; } else if (valueType == typeof(decimal) || valueType == typeof(double) || valueType == typeof(float)) { item.FilteringType = "Decimal"; } else if (valueType == typeof(int) || valueType == typeof(short) || valueType == typeof(long)) { item.FilteringType = "Integer"; } else { item.FilteringType = "String"; } }
private static void SetFiltering(IPropertySource source, PropertyItem item) { var filterOnlyAttr = source.GetAttribute <FilterOnlyAttribute>(); var notFilterableAttr = source.GetAttribute <NotFilterableAttribute>(); if (filterOnlyAttr != null && filterOnlyAttr.Value) { item.FilterOnly = true; } if (notFilterableAttr != null && notFilterableAttr.Value) { item.NotFilterable = true; } if (item.NotFilterable == true) { return; } var quickFilterAttr = source.GetAttribute <QuickFilterAttribute>(); if (quickFilterAttr != null) { item.QuickFilter = true; if (quickFilterAttr.Separator) { item.QuickFilterSeparator = true; } if (!string.IsNullOrEmpty(quickFilterAttr.CssClass)) { item.QuickFilterCssClass = quickFilterAttr.CssClass; } } var basedOnField = source.BasedOnField; if (!ReferenceEquals(null, basedOnField) && notFilterableAttr == null) { if (basedOnField.Flags.HasFlag(FieldFlags.DenyFiltering) || basedOnField.Flags.HasFlag(FieldFlags.NotMapped)) { item.NotFilterable = true; } } Field idField; string idFieldName; var filteringIdField = source.GetAttribute <FilteringIdFieldAttribute>(); if (filteringIdField != null) { idFieldName = filteringIdField.Value; idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); } else { idFieldName = AutoDetermineIdField(basedOnField); idField = null; if (idFieldName != null) { idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); if (Object.ReferenceEquals(idField, null) || (idField.TextualField != basedOnField.PropertyName && idField.TextualField != basedOnField.Name)) { idField = null; idFieldName = null; } } } var valueType = source.ValueType; var filteringTypeAttr = source.GetAttribute <FilteringTypeAttribute>() ?? idField.GetAttribute <FilteringTypeAttribute>(); if (filteringTypeAttr == null) { var editorAttr = source.GetAttribute <EditorTypeAttribute>() ?? idField.GetAttribute <EditorTypeAttribute>(); Action <string[]> copyParamsFromEditor = (keys) => { var prm = new Dictionary <string, object>(); editorAttr.SetParams(prm); SetServiceLookupParams(editorAttr, prm); foreach (var key in keys) { if (prm.TryGetValue(key, out object o)) { item.FilteringParams[key] = o; } } }; if (idFieldName != null) { item.FilteringParams["idField"] = idFieldName; item.FilteringIdField = idFieldName; } if (editorAttr != null && !standardFilteringEditors.Contains(editorAttr.EditorType)) { if (editorAttr is LookupEditorAttribute lea) { item.FilteringType = "Lookup"; copyParamsFromEditor(lookupCopyToFilterParams); } else if (editorAttr is ServiceLookupEditorAttribute slea) { item.FilteringType = "ServiceLookup"; copyParamsFromEditor(serviceLookupCopyToFilterParams); } else { item.FilteringType = "Editor"; item.FilteringParams["editorType"] = editorAttr.EditorType; item.FilteringParams["useLike"] = source.ValueType == typeof(String); if (editorAttr is LookupEditorBaseAttribute leba && leba.Async == true) { item.FilteringParams["async"] = true; } } } else if (source.EnumType != null) { item.FilteringType = "Enum"; item.FilteringParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } else if (valueType == typeof(DateTime)) { if (!ReferenceEquals(null, basedOnField) && basedOnField is DateTimeField && !((DateTimeField)basedOnField).DateOnly) { item.FilteringType = "DateTime"; } else { item.FilteringType = "Date"; } } else if (valueType == typeof(Boolean)) { item.FilteringType = "Boolean"; } else if (valueType == typeof(Decimal) || valueType == typeof(Double) || valueType == typeof(Single)) { item.FilteringType = "Decimal"; } else if (valueType == typeof(Int32) || valueType == typeof(Int16) || valueType == typeof(Int64)) { item.FilteringType = "Integer"; } else { item.FilteringType = "String"; } } else { item.FilteringType = filteringTypeAttr.FilteringType; filteringTypeAttr.SetParams(item.FilteringParams); if (item.FilteringType == "Editor") { if (!item.FilteringParams.ContainsKey("editorType")) { var editorAttr = source.GetAttribute <EditorTypeAttribute>() ?? idField.GetAttribute <EditorTypeAttribute>(); if (editorAttr != null) { item.FilteringParams["editorType"] = editorAttr.EditorType; } } if (!item.FilteringParams.ContainsKey("useLike")) { if (valueType == typeof(String)) { item.FilteringParams["useLike"] = true; } } } object idFieldObj; if (item.FilteringParams.TryGetValue("idField", out idFieldObj) && idFieldObj is string) { item.FilteringIdField = (idFieldObj as string).TrimToNull(); } else { item.FilteringIdField = idFieldName; } } var displayFormatAttr = source.GetAttribute <DisplayFormatAttribute>(); if (displayFormatAttr != null) { item.FilteringParams["displayFormat"] = displayFormatAttr.Value; } foreach (FilteringOptionAttribute param in idField.GetAttributes <FilteringOptionAttribute>().Concat( source.GetAttributes <FilteringOptionAttribute>())) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } if (key == "idField") { item.FilteringIdField = (param.Value as string) ?? item.FilteringIdField; } item.FilteringParams[key] = param.Value; } foreach (QuickFilterOptionAttribute param in idField.GetAttributes <QuickFilterOptionAttribute>().Concat( source.GetAttributes <QuickFilterOptionAttribute>())) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.QuickFilterParams[key] = param.Value; } }
private static void SetFiltering(IPropertySource source, PropertyItem item) { var filterOnlyAttr = source.GetAttribute <FilterOnlyAttribute>(); var notFilterableAttr = source.GetAttribute <NotFilterableAttribute>(); if (filterOnlyAttr != null && filterOnlyAttr.Value) { item.FilterOnly = true; } if (notFilterableAttr != null && notFilterableAttr.Value) { item.NotFilterable = true; } if (item.NotFilterable == true) { return; } var quickFilterAttr = source.GetAttribute <QuickFilterAttribute>(); if (quickFilterAttr != null) { item.QuickFilter = true; if (quickFilterAttr.Separator) { item.QuickFilterSeparator = true; } if (!string.IsNullOrEmpty(quickFilterAttr.CssClass)) { item.QuickFilterCssClass = quickFilterAttr.CssClass; } } var basedOnField = source.BasedOnField; if (!ReferenceEquals(null, basedOnField) && notFilterableAttr == null) { if (basedOnField.Flags.HasFlag(FieldFlags.DenyFiltering) || basedOnField.Flags.HasFlag(FieldFlags.NotMapped)) { item.NotFilterable = true; } } Field idField; string idFieldName; var filteringIdField = source.GetAttribute <FilteringIdFieldAttribute>(); if (filteringIdField != null) { idFieldName = filteringIdField.Value; idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); } else { idFieldName = AutoDetermineIdField(basedOnField); idField = null; if (idFieldName != null) { idField = basedOnField.Fields.FindFieldByPropertyName(idFieldName) ?? basedOnField.Fields.FindField(idFieldName); if (Object.ReferenceEquals(idField, null) || (idField.TextualField != basedOnField.PropertyName && idField.TextualField != basedOnField.Name)) { idField = null; idFieldName = null; } } } var valueType = source.ValueType; var filteringTypeAttr = source.GetAttribute <FilteringTypeAttribute>() ?? idField.GetAttribute <FilteringTypeAttribute>(); if (filteringTypeAttr == null) { var editorAttr = source.GetAttribute <EditorTypeAttribute>() ?? idField.GetAttribute <EditorTypeAttribute>(); if (idFieldName != null) { item.FilteringParams["idField"] = idFieldName; item.FilteringIdField = idFieldName; } if (editorAttr != null && !standardFilteringEditors.Contains(editorAttr.EditorType)) { if (editorAttr is LookupEditorAttribute || editorAttr is AsyncLookupEditorAttribute) { var async = editorAttr as AsyncLookupEditorAttribute; item.FilteringType = async != null ? "AsyncLookup" : "Lookup"; item.FilteringParams["lookupKey"] = async != null ? async.LookupKey : ((LookupEditorAttribute)editorAttr).LookupKey; } else { item.FilteringType = "Editor"; item.FilteringParams["editorType"] = editorAttr.EditorType; item.FilteringParams["useLike"] = source.ValueType == typeof(String); } } else if (source.EnumType != null) { item.FilteringType = "Enum"; item.FilteringParams["enumKey"] = EnumMapper.GetEnumTypeKey(source.EnumType); } else if (valueType == typeof(DateTime)) { if (!ReferenceEquals(null, basedOnField) && basedOnField is DateTimeField) { switch (((DateTimeField)basedOnField).DateTimeKind) { case DateTimeKind.Unspecified: item.FilteringType = "Date"; break; default: item.FilteringType = "DateTime"; break; } } else { item.FilteringType = "Date"; } } else if (valueType == typeof(Boolean)) { item.FilteringType = "Boolean"; } else if (valueType == typeof(Decimal) || valueType == typeof(Double) || valueType == typeof(Single)) { item.FilteringType = "Decimal"; } else if (valueType == typeof(Int32) || valueType == typeof(Int16) || valueType == typeof(Int64)) { item.FilteringType = "Integer"; } else { item.FilteringType = "String"; } } else { item.FilteringType = filteringTypeAttr.FilteringType; filteringTypeAttr.SetParams(item.FilteringParams); if (item.FilteringType == "Editor") { if (!item.FilteringParams.ContainsKey("editorType")) { var editorAttr = source.GetAttribute <EditorTypeAttribute>() ?? idField.GetAttribute <EditorTypeAttribute>(); if (editorAttr != null) { item.FilteringParams["editorType"] = editorAttr.EditorType; } } if (!item.FilteringParams.ContainsKey("useLike")) { if (valueType == typeof(String)) { item.FilteringParams["useLike"] = true; } } } object idFieldObj; if (item.FilteringParams.TryGetValue("idField", out idFieldObj) && idFieldObj is string) { item.FilteringIdField = (idFieldObj as string).TrimToNull(); } else { item.FilteringIdField = idFieldName; } } var displayFormatAttr = source.GetAttribute <DisplayFormatAttribute>(); if (displayFormatAttr != null) { item.FilteringParams["displayFormat"] = displayFormatAttr.Value; } foreach (FilteringOptionAttribute param in idField.GetAttributes <FilteringOptionAttribute>().Concat( source.GetAttributes <FilteringOptionAttribute>())) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } if (key == "idField") { item.FilteringIdField = (param.Value as string) ?? item.FilteringIdField; } item.FilteringParams[key] = param.Value; } foreach (QuickFilterOptionAttribute param in idField.GetAttributes <QuickFilterOptionAttribute>().Concat( source.GetAttributes <QuickFilterOptionAttribute>())) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.QuickFilterParams[key] = param.Value; } }
private static void SetFormatting(IPropertySource source, PropertyItem item) { var formatterTypeAttr = source.GetAttribute <FormatterTypeAttribute>(); var enumType = source.EnumType; var valueType = source.ValueType; var basedOnField = source.BasedOnField; if (formatterTypeAttr == null) { if (enumType != null) { item.FormatterType = "Enum"; item.FormatterParams["enumKey"] = EnumMapper.GetEnumTypeKey(enumType); } else if (valueType == typeof(DateTime) || valueType == typeof(DateTime?)) { if (!ReferenceEquals(null, basedOnField) && basedOnField is DateTimeField && !((DateTimeField)basedOnField).DateOnly) { item.FormatterType = "DateTime"; } else { item.FormatterType = "Date"; } } else if (valueType == typeof(Boolean)) { item.FormatterType = "Checkbox"; } else if (valueType == typeof(Decimal) || valueType == typeof(Double) || valueType == typeof(Single) || valueType == typeof(Int32)) { item.FormatterType = "Number"; } } else { item.FormatterType = formatterTypeAttr.FormatterType; formatterTypeAttr.SetParams(item.FormatterParams); } var displayFormatAttr = source.GetAttribute <DisplayFormatAttribute>(); if (displayFormatAttr != null) { item.DisplayFormat = displayFormatAttr.Value; item.FormatterParams["displayFormat"] = displayFormatAttr.Value; } foreach (FormatterOptionAttribute param in source.GetAttributes <FormatterOptionAttribute>()) { var key = param.Key; if (key != null && key.Length >= 1) { key = key.Substring(0, 1).ToLowerInvariant() + key.Substring(1); } item.FormatterParams[key] = param.Value; } }