コード例 #1
0
        private IEnumerable <SelectListItem> GetSelectList(Enum[] excludeEnums)
        {
            var enumValues = Enum.GetValues(FieldGenerator.GetUnderlyingType());

            foreach (var i in enumValues)
            {
                if (excludeEnums.Contains(i))
                {
                    continue;
                }

                yield return(new SelectListItem
                {
                    Text = (i as Enum).Humanize(),
                    Value = i.ToString(),
                    Selected = FieldGenerator.IsSelected(i)
                });
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public override void PrepareFieldConfiguration(IFieldConfiguration fieldConfiguration)
        {
            if (!fieldConfiguration.Attributes.Has("step"))
            {
                if (FieldGenerator.IsIntegralNumber())
                {
                    fieldConfiguration.Attr("step", 1);
                }
                else if (FieldGenerator.Metadata.DataTypeName == DataType.Currency.ToString())
                {
                    fieldConfiguration.Attr("step", 0.01);
                }
                else
                {
                    fieldConfiguration.Attr("step", "any");
                }
            }

            if (!fieldConfiguration.Attributes.Has("min") || !fieldConfiguration.Attributes.Has("max"))
            {
                object min = null;
                object max = null;

                if (FieldGenerator.GetCustomAttributes().OfType <RangeAttribute>().Any())
                {
                    var converter = TypeDescriptor.GetConverter(FieldGenerator.GetUnderlyingType());
                    var range     = FieldGenerator.GetCustomAttributes().OfType <RangeAttribute>().First();
                    min = range.Minimum;
                    max = range.Maximum;
                }
                else
                {
                    var type = FieldGenerator.GetUnderlyingType();

                    // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types
                    if (type == typeof(byte))
                    {
                        min = 0;
                        max = 255;
                    }
                    if (type == typeof(sbyte))
                    {
                        min = -128;
                        max = 127;
                    }
                    if (type == typeof(short))
                    {
                        min = -32768;
                        max = 32767;
                    }
                    if (type == typeof(ushort))
                    {
                        min = 0;
                        max = 65535;
                    }
                    if (type == typeof(uint))
                    {
                        min = 0;
                    }
                    if (type == typeof(ulong))
                    {
                        min = 0;
                    }
                }

                if (!fieldConfiguration.Attributes.Has("min") && min != null)
                {
                    fieldConfiguration.Min(min.ToString());
                }
                if (!fieldConfiguration.Attributes.Has("max") && max != null)
                {
                    fieldConfiguration.Max(max.ToString());
                }
            }
        }
コード例 #3
0
 /// <inheritdoc />
 public override bool CanHandle()
 {
     return(FieldGenerator.GetUnderlyingType() == typeof(DateTime));
 }
コード例 #4
0
 /// <inheritdoc />
 public override bool CanHandle()
 {
     return(FieldGenerator.GetUnderlyingType() == typeof(bool) &&
            !FieldGenerator.HasEnumerableValues());
 }
コード例 #5
0
 /// <inheritdoc />
 public override bool CanHandle()
 {
     return(FieldGenerator.GetUnderlyingType().IsEnum);
 }