public void TestIListValueType_Success()
        {
            var serializer = this.CreateTarget <ListValueType <int> >(GetSerializationContext());

            using (var stream = new MemoryStream())
            {
                var value = new ListValueType <int>(3)
                {
                    1, 2, 3
                };
                serializer.Pack(stream, value);
                stream.Position = 0;
                var result = serializer.Unpack(stream);
                Assert.That(result.ToArray(), Is.EqualTo(new int[] { 1, 2, 3 }));
            }
        }
Example #2
0
        public static MvcHtmlString CategoryListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, int categoryParentId, object htmlAttributes = null, string emptyOption = null, ListValueType valueType = ListValueType.Value)
        {
            List <SelectListItem> items = new List <SelectListItem>();

            if (!string.IsNullOrEmpty(emptyOption))
            {
                items.Add(new SelectListItem {
                    Text = emptyOption, Value = string.Empty
                });
            }

            items.AddRange(Resolve <ICategoryService>().List(categoryParentId).Select(x => new SelectListItem
            {
                Text  = x.Title,
                Value = valueType == ListValueType.Text ? x.Title : x.CategoryId.HasValue ? x.CategoryId.ToString() : string.Empty
            }));

            return(htmlHelper.DropDownListFor(expression, items, htmlAttributes));
        }
Example #3
0
        public void CommaSeparatedList(IEnumerable <object> values, TypeReferenceContext context, ListValueType valueType = ListValueType.Primitive)
        {
            CommaSeparatedListCore(
                values, (value) => {
                if (valueType == ListValueType.Primitive)
                {
                    Value(value as dynamic);
                }
                else if (valueType == ListValueType.Identifier)
                {
                    Identifier(value as dynamic, context);
                }
                else if (valueType == ListValueType.TypeIdentifier)
                {
                    TypeIdentifier(value as dynamic, context, false);
                }
                else if (valueType == ListValueType.TypeReference)
                {
                    TypeReference((TypeReference)value, context);
                }
                else
                {
                    WriteRaw(value.ToString());
                }
            },

                ((valueType == ListValueType.TypeIdentifier) || (valueType == ListValueType.TypeReference)) ?
                2 : 4
                );
        }