Пример #1
0
        public static Func <object, PropertyInfo, Func <object>, Action <object>, object> ChoicesWithRadioButtons(
            IEnumerable <object> choices, NullableOptionInclusionKind nullKind, Func <object, string> toString = null) =>
        (o, p, gv, sv) =>
        {
            var group = Guid.NewGuid().ToString();
            var v     = gv();

            var radioButtons =
                choices
                .Select(x => new RadioButton(@group, toString?.Invoke(x) ?? $"{x}", x.Equals(v), b => sv(x)))
                .ToList();

            var nullOption = new RadioButton(@group, NullString, v == null, _ => sv(null));
            switch (nullKind)
            {
            case NullableOptionInclusionKind.IncludeAtStart:
                radioButtons.Insert(0, nullOption);
                break;

            case NullableOptionInclusionKind.IncludeAtEnd:
                radioButtons.Add(nullOption);
                break;
            }

            return(Util.HorizontalRun((bool)true, (IEnumerable)radioButtons));
        };
Пример #2
0
        public static Func <object, PropertyInfo, Func <object>, Action <object>, object> ChoicesWithHyperlinqs <T>(
            IEnumerable <T> choices, NullableOptionInclusionKind nullKind, Func <T, string> toString = null) =>
        (o, p, gv, sv) =>
        {
            var preceding = new object[] { gv(), "[" };
            var trailing  = new object[] { "]" };

            var values = choices.Select(x => new Hyperlinq(() => sv(x), toString?.Invoke(x) ?? $"{x}")).ToList();

            var nullOption = new Hyperlinq(() => sv(null), NullString);

            switch (nullKind)
            {
            case NullableOptionInclusionKind.IncludeAtStart:
                values.Insert(0, nullOption);
                break;

            case NullableOptionInclusionKind.IncludeAtEnd:
                values.Add(nullOption);
                break;
            }

            return(Util.HorizontalRun(
                       true,
                       Enumerable.Concat(
                           new object[] { gv(), "[" },
                           choices.Select(x => new Hyperlinq(() => sv(x), toString?.Invoke(x) ?? $"{x}")))
                       .Concat(new[] { "]" })));
        };
Пример #3
0
 public static Func <object, PropertyInfo, Func <object>, Action <object>, object> ChoicesWithRadioButtons <T>(
     IEnumerable <T> choices, NullableOptionInclusionKind nullKind, Func <T, string> toString = null) =>
 ChoicesWithRadioButtons(choices.OfType <object>(), nullKind, o => toString((T)o));