コード例 #1
0
 public override void Process(IPropertySource source, PropertyItem item)
 {
     SetAlignment(source, item);
     SetCategory(source, item);
     SetCssClass(source, item);
     SetDefaultValue(source, item);
     SetEditLink(source, item);
     SetEditing(source, item);
     SetFiltering(source, item);
     SetFormatting(source, item);
     SetHideOnInsert(source, item);
     SetHideOnUpdate(source, item);
     SetHint(source, item);
     SetInsertable(source, item);
     SetOneWay(source, item);
     SetPlaceholder(source, item);
     SetReadOnly(source, item);
     SetRequired(source, item);
     SetResizable(source, item);
     SetSorting(source, item);
     SetTitle(source, item);
     SetUpdatable(source, item);
     SetVisible(source, item);
     SetWidth(source, item);
 }
コード例 #2
0
        private void SetTitle(IPropertySource source, PropertyItem item)
        {
            if (source.Property != null)
            {
                var attr = source.Property.GetCustomAttribute<DisplayNameAttribute>(false);
                if (attr != null)
                    item.Title = attr.DisplayName;
            }

            if (item.Title == null)
            {
                var basedOnField = source.BasedOnField;

                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))
                    {
                        item.Title = !object.ReferenceEquals(null, textualField.Caption) ?
                            textualField.Caption.Key : textualField.Title;
                    }
                    else
                    {
                        item.Title = !object.ReferenceEquals(null, basedOnField.Caption) ?
                            basedOnField.Caption.Key : basedOnField.Title;
                    }
                }
                else
                    item.Title = item.Name;
            }
        }
コード例 #3
0
        public void IgnoresFieldDeclarations()
        {
            var actual = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithField));
            var expected = new PropertyItem[0];

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
コード例 #4
0
 private void SetCategory(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<CategoryAttribute>();
     if (attr != null)
         item.Category = attr.Category;
     else if (Items != null && Items.Count > 0)
         item.Category = Items[Items.Count - 1].Category;
 }
コード例 #5
0
        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 (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;
            }
        }
コード例 #6
0
        public void Returns_One_Element_List_For_ClassWithOneSimpleProperty()
        {
            var actual = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithOneSimpleProperty));
            var expected = new PropertyItem[]
            {
                new PropertyItem { Name = "Property", Title = "Property", Width = 80 }
            };

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
コード例 #7
0
        private void SetCssClass(IPropertySource source, PropertyItem item)
        {
            var attr = source.GetAttribute<CssClassAttribute>();
            if (attr != null)
                item.CssClass = attr.CssClass;

            var hattr = source.GetAttribute<HeaderCssClassAttribute>();
            if (hattr != null)
                item.HeaderCssClass = hattr.Value;
        }
コード例 #8
0
        private void SetSorting(IPropertySource source, PropertyItem item)
        {
            var sortOrderAttr = source.GetAttribute<SortOrderAttribute>();
            if (sortOrderAttr != null && sortOrderAttr.SortOrder != 0)
                item.SortOrder = sortOrderAttr.SortOrder;

            var sortableAttr = source.GetAttribute<SortableAttribute>();
            if (sortableAttr != null && !sortableAttr.Value)
                item.Sortable = false;
        }
コード例 #9
0
 private void SetCollapsible(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<CollapsibleAttribute>();
     if (attr != null && attr.Value)
     {
         item.Collapsible = true;
         if (attr.Collapsed)
             item.Collapsed = true;
     }
 }
コード例 #10
0
        private void SetWidth(IPropertySource source, PropertyItem item)
        {
            var widthAttr = source.GetAttribute<WidthAttribute>();
            var basedOnField = source.BasedOnField;
            item.Width = widthAttr == null ? (!ReferenceEquals(null, basedOnField) ? AutoWidth(basedOnField) : 80) : widthAttr.Value;
            if (widthAttr != null && (widthAttr.Min != 0))
                item.MinWidth = widthAttr.Min;

            if (widthAttr != null && (widthAttr.Max != 0))
                item.MaxWidth = widthAttr.Max;
        }
コード例 #11
0
        public void PreservesDeclarationOrderingFor_ClassWithUnorderedProperties()
        {
            var actual = PropertyItemHelper.GetPropertyItemsFor(typeof(ClassWithUnorderedProperties));

            var expected = new PropertyItem[]
            {
                new PropertyItem { Name = "Property3", Title = "Property3", Width = 80 },
                new PropertyItem { Name = "Property1", Title = "Property1", Width = 80 },
                new PropertyItem { Name = "Property2", Title = "Property2", Width = 80 }
            };

            Assert.Equal(JSON.StringifyIndented(expected), JSON.StringifyIndented(actual));
        }
コード例 #12
0
 private void SetRequired(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<RequiredAttribute>();
     if (attr != null)
     {
         if (attr.IsRequired)
             item.Required = true;
     }
     else if (!ReferenceEquals(null, source.BasedOnField) &&
         (source.BasedOnField.Flags & FieldFlags.NotNull) == FieldFlags.NotNull)
     {
         item.Required = true;
     }
 }
コード例 #13
0
        private void SetDefaultValue(IPropertySource source, PropertyItem item)
        {
            if (source.Property != null)
            {
                var attr = source.Property.GetAttribute<DefaultValueAttribute>(false);
                if (attr != null)
                {
                    item.DefaultValue = attr.Value;
                    return;
                }
            }

            if (!ReferenceEquals(null, source.BasedOnField) && source.BasedOnField.DefaultValue != null)
                item.DefaultValue = source.BasedOnField.DefaultValue;
        }
コード例 #14
0
        public override void Process(IPropertySource source, PropertyItem item)
        {
            var attr = source.GetAttribute<LocalizableAttribute>();
            if (attr != null)
            {
                item.Localizable = true;
                return;
            }

            if (!ReferenceEquals(null, source.BasedOnField) &&
                localizationRowHandler != null &&
                localizationRowHandler.IsLocalized(source.BasedOnField))
            {
                item.Localizable = true;
            }
        }
コード例 #15
0
        private ReportColumn FromPropertyItem(PropertyItem item, Field field)
        {
            var result = new ReportColumn();
            result.Name = item.Name;
            result.Title = item.Title ?? item.Name;
            if (result.Title != null)
                result.Title = LocalText.TryGet(result.Title) ?? result.Title;

            if (item.Width != null)
                result.Width = item.Width;

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
                result.Format = item.DisplayFormat;
            else
            {
                var dtf = field as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            var enumField = field as IEnumTypeField;
            if (enumField != null && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType);
            }

            if (!ReferenceEquals(null, field))
            {
                if (result.Title == null)
                    result.Title = field.Title;

                if (result.Width == null && field is StringField && field.Size != 0)
                    result.Width = field.Size;
            }

            result.DataType = !ReferenceEquals(null, field) ? field.ValueType : null;

            return result;
        }
コード例 #16
0
        private void SetSorting(IPropertySource source, PropertyItem item)
        {
            var sortOrderAttr = source.GetAttribute<SortOrderAttribute>();
            if (sortOrderAttr != null && sortOrderAttr.SortOrder != 0)
                item.SortOrder = sortOrderAttr.SortOrder;

            var sortableAttr = source.GetAttribute<SortableAttribute>();
            if (sortableAttr != null)
            {
                if (!sortableAttr.Value)
                    item.Sortable = false;

                return;
            }

            if (!ReferenceEquals(null, source.BasedOnField) &&
                source.BasedOnField.Flags.HasFlag(FieldFlags.NotMapped))
                    item.Sortable = false;
        }
コード例 #17
0
        private void SetInsertable(IPropertySource source, PropertyItem item)
        {
            if (source.Property != null)
            {
                var attr = source.Property.GetAttribute<InsertableAttribute>(false);
                if (attr != null)
                {
                    if (!attr.Value)
                        item.Insertable = false;

                    return;
                }
            }

            if (!ReferenceEquals(null, source.BasedOnField))
            {
                if ((source.BasedOnField.Flags & FieldFlags.Insertable) != FieldFlags.Insertable)
                    item.Insertable = false;
            }
        }
コード例 #18
0
        public static List<PropertyItem> GetPropertyItemsFor(Type type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            var list = new List<PropertyItem>();

            var basedOnRow = GetBasedOnRow(type);
            var processors = ProcessorTypes.Select(x => (IPropertyProcessor)Activator.CreateInstance(x))
                .OrderBy(x => x.Priority).ToList();

            foreach (var processor in processors)
            {
                processor.Items = list;
                processor.Type = type;
                processor.BasedOnRow = basedOnRow;
                processor.Initialize();
            }

            foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .OrderBy(x => x.MetadataToken))
            {
                if (property.GetCustomAttribute<IgnoreAttribute>(false) != null)
                    continue;

                var source = new PropertyInfoSource(property, basedOnRow);

                PropertyItem pi = new PropertyItem();
                pi.Name = property.Name;

                foreach (var processor in processors)
                    processor.Process(source, pi);

                list.Add(pi);
            }

            foreach (var processor in processors)
                processor.PostProcess();

            return list;
        }
コード例 #19
0
        private void SetUpdatePermission(IPropertySource source, PropertyItem item)
        {
            if (source.Property != null)
            {
                var attr = source.Property.GetAttribute<UpdatePermissionAttribute>(false);
                if (attr != null)
                {
                    if (attr.Permission != "*")
                        item.UpdatePermission = attr.Permission ?? "?";

                    return;
                }
            }

            if (!ReferenceEquals(null, source.BasedOnField))
            {
                if (source.BasedOnField.UpdatePermission != null &&
                    source.BasedOnField.UpdatePermission != "*")
                    item.UpdatePermission = source.BasedOnField.UpdatePermission;
            }
        }
コード例 #20
0
        private void SetEditLink(IPropertySource source, PropertyItem item)
        {
            var attr = source.GetAttribute<EditLinkAttribute>();
            if (attr == null)
                return;

            if (attr.Value)
                item.EditLink = true;

            if (attr.ItemType != null)
                item.EditLinkItemType = attr.ItemType;

            if (attr.IdField != null)
                item.EditLinkIdField = attr.IdField;

            if (attr.CssClass != null)
                item.EditLinkCssClass = attr.CssClass;

            if (item.EditLinkItemType != null &&
                item.EditLinkIdField == null)
            {
                item.EditLinkIdField = AutoDetermineIdField(source.BasedOnField);
            }
        }
コード例 #21
0
 private void SetReadOnly(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<ReadOnlyAttribute>();
     if (attr != null)
         item.ReadOnly = true;
 }
コード例 #22
0
 private void SetAlignment(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<AlignmentAttribute>();
     if (attr != null)
         item.Alignment = attr.Value;
 }
コード例 #23
0
        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)
                    {
                        switch (((DateTimeField)basedOnField).DateTimeKind)
                        {
                            case DateTimeKind.Unspecified:
                                item.FormatterType = "Date";
                                break;
                            default:
                                item.FormatterType = "DateTime";
                                break;
                        }
                    }
                    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;
            }
        } 
コード例 #24
0
 private void SetHideOnUpdate(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<HideOnUpdateAttribute>();
     if (attr != null && attr.Value)
         item.HideOnUpdate = true;
 }
コード例 #25
0
        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 && quickFilterAttr.Value)
                item.QuickFilter = true;

            var basedOnField = source.BasedOnField;

            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;
            }
        }
コード例 #26
0
 private void SetPlaceholder(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<PlaceholderAttribute>();
     if (attr != null)
         item.Placeholder = attr.Value;
 }
コード例 #27
0
 private void SetCssClass(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<CssClassAttribute>();
     if (attr != null)
         item.CssClass = attr.CssClass;
 }
コード例 #28
0
        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;
        }
コード例 #29
0
 private void SetVisible(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<VisibleAttribute>();
     if (attr != null && attr.Value == false)
         item.Visible = false;
 }
コード例 #30
0
 private void SetSortOrder(IPropertySource source, PropertyItem item)
 {
     var attr = source.GetAttribute<SortOrderAttribute>();
     if (attr != null && attr.SortOrder != 0)
         item.SortOrder = attr.SortOrder;
 }