Exemplo n.º 1
0
        public Task BindModelAsync([NotNull] ModelBindingContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ValueProviderResult valueProviderResult =
                context.ValueProvider.GetValue(context.ModelName);

            if (valueProviderResult == ValueProviderResult.None)
            {
                return(Task.CompletedTask);
            }

            context.ModelState.SetModelValue(context.ModelName, valueProviderResult);

            GroupingValues <string, string> model =
                GroupingValues <string, string> .Parse(valueProviderResult.Values);

            context.Result =
                ModelBindingResult.Success(model);

            return(Task.CompletedTask);
        }
        public void GroupingValues(string value, int groupCount)
        {
            GroupingValues <string, string> groups = GroupingValues <string, string> .Parse(value);

            Assert.Equal(groupCount, groups.Select(x => x.Key).Count());
            Assert.Equal(groupCount, groups.Count());
            Assert.True(groups.Individuals.All(x => !x.Contains(',')));
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            switch (value)
            {
            case string s:
            {
                return(GroupingValues <string, string> .Parse(s));
            }

            case StringValues s:
            {
                return(GroupingValues <string, string> .Parse(s));
            }

            default:
            {
                return(base.ConvertFrom(context, culture, value));
            }
            }
        }