Ejemplo n.º 1
0
 public override void Fill(DateTimePropertyBag propertyBag, FillerParams fillerParams)
 {
     FillLiteral(propertyBag, fillerParams);
 }
Ejemplo n.º 2
0
 public override void Fill(DateTimePropertyBag propertyBag, FillerParams fillerParams)
 {
     FillLiteral(propertyBag, fillerParams);
 }
        internal PropertyBag GetBagFromProperty(PropertyInfo property, Type entityType)
        {
            var bag = new PropertyBag()
            {
                DisplayAs         = property.TryGetAttribute <DisplayAttribute>(out var display) ? display.Label : null,
                Subtitle          = property.TryGetAttribute <SubtitleAttribute>(out var subtitle) ? subtitle.SubTitle : null,
                EnabledWhenSource = property.TryGetAttribute <IsEnabledPropertyAttribute>(out var isEnabled) ? isEnabled.PropertyToBind : null,
                //EnabledWhen = property.TryGetAttribute<IsEnabledPropertyAttribute>(out var isEnabled) ?
                WithOrder = property.TryGetAttribute <PropertyOrderAttribute>(out var order) ? order.Order : 0,
                Required  = property.TryGetAttribute <System.ComponentModel.DataAnnotations.RequiredAttribute>(out var required)
            };


            var propertyType = property.PropertyType;

            if (propertyType.Equals(typeof(int)) ||
                propertyType.Equals(typeof(long)) ||
                propertyType.Equals(typeof(int?)) ||
                propertyType.Equals(typeof(long?)))
            {
                if (property.TryGetAttribute <IsNumericAttribute>(out var isNumeric))
                {
                    bag = new NumericPropertyBag(bag)
                    {
                        NumberOfDecimals  = property.TryGetAttribute <DecimalCountAttribute>(out var decimalCount) ? decimalCount.Number : 0,
                        AutoIncrementStep = property.TryGetAttribute <AutoIncrementAttribute>(out var autoIncrement) ? autoIncrement.Step : 0,
                        Range             = property.TryGetAttribute <RangeAttribute>(out var range) ? (range.Min, range.Max) : (0, 0)
                    };
                }
                else
                {
                    bag = new StringPropertyBag(bag)
                    {
                        Multiline     = property.TryGetAttribute <MultilineAttribute>(out var multiline),
                        Length        = property.TryGetAttribute <StringLengthAttribute>(out var length) ? length.Count : 0,
                        MinAndMaxSize = property.TryGetAttribute <MinMaxSizeAttribute>(out var minMaxSize) ?
                                        (minMaxSize.MinWidth, minMaxSize.MinHeight, minMaxSize.MaxWidth, minMaxSize.MaxHeight) :
                                        (0, 0, 0, 0)
                    };
                }
            }

            if (propertyType.Equals(typeof(string)))
            {
                if (property.TryGetAttribute <IsSuggestionsEnabledAttribute>(out var isSuggestion))
                {
                    bag = new AutoSuggestionPropertyBag(bag)
                    {
                        CollectionSourcePropertyName = isSuggestion.CollectionBindingDisplayName,
                        CollectionName = isSuggestion.CollectionName
                    };
                }
                else
                {
                    bag = new StringPropertyBag(bag)
                    {
                        Multiline = property.TryGetAttribute <MultilineAttribute>(out var multiline),
                        Length    = property.TryGetAttribute <StringLengthAttribute>(out var length) ? length.Count : 0
                    };
                    //TODO: As a regular string
                }
            }

            if (propertyType.Equals(typeof(float)) ||
                propertyType.Equals(typeof(decimal)) ||
                propertyType.Equals(typeof(double)) ||
                propertyType.Equals(typeof(double?)) ||
                propertyType.Equals(typeof(decimal?)) ||
                propertyType.Equals(typeof(float?))

                )
            {
                bag = new NumericPropertyBag(bag)
                {
                    NumberOfDecimals  = property.TryGetAttribute <DecimalCountAttribute>(out var decimalCount) ? decimalCount.Number : 0,
                    AutoIncrementStep = property.TryGetAttribute <AutoIncrementAttribute>(out var autoIncrement) ? autoIncrement.Step : 0,
                    Range             = property.TryGetAttribute <RangeAttribute>(out var range) ? (range.Min, range.Max) : (0, 0)
                };
            }

            var tColl = typeof(ICollection <>);

            if (propertyType.GetTypeInfo().IsGenericType&& tColl.IsAssignableFrom(propertyType.GetGenericTypeDefinition()) ||
                propertyType.GetInterfaces().Any(x => x.GetTypeInfo().IsGenericType&& x.GetGenericTypeDefinition() == tColl))
            {
                bag = new CollectionPropertyBag(bag)
                {
                    DisplayMemberPath = property.TryGetAttribute <DisplayMemberPathCollectionAttribute>(out var displayMember) ? displayMember.DisplayMemberPath : null,
                    SelectedItemPath  = property.TryGetAttribute <SelectedItemCollectionAttribute>(out var selected) ? selected.PropertyNameToBind : null
                };
            }

            if (propertyType.Equals(typeof(DateTime)) || propertyType.Equals(typeof(DateTime?)))
            {
                bag = new DateTimePropertyBag(bag);
            }

            if (propertyType.Equals(typeof(bool)) || propertyType.Equals(typeof(bool?)))
            {
                bag = new BooleanPropertyBag(bag);
            }

            if (propertyType.Equals(typeof(TimeSpan)) || propertyType.Equals(typeof(TimeSpan?)))
            {
                bag = new TimeSpanPropertyBag(bag)
                {
                    MinuteIncrement = property.TryGetAttribute <MinuteIncrementAttribute>(out var increment) ? increment.Number : 0,
                    ClockFormat     = property.TryGetAttribute <ClockIdentifierAttribute>(out var format) ? format.ClockFormat : null
                };
            }

            return(bag);
        }
    }
}