Exemplo n.º 1
0
        private static Func <IActor, ITarget, CultureInfo, object> ApplyGetConverter(
#pragma warning disable S1172 // Unused method parameters should be removed. False positive
            ITarget target,
#pragma warning restore S1172 // Unused method parameters should be removed
            Type type,
#pragma warning disable S1172 // Unused method parameters should be removed. False positive
            UIStateAttribute uiStateAttribute)
#pragma warning restore S1172 // Unused method parameters should be removed
        {
            if (type == typeof(int))
            {
                return(GetFunction(_integerConverters));
            }
            if (type == typeof(string))
            {
                return(GetFunction(_textConverters));
            }
            if (type == typeof(bool))
            {
                return(GetFunction(_booleanConverters));
            }
            if (type == typeof(DateTime))
            {
                return(GetFunction(_dateTimeConverters));
            }
            if (type == typeof(double))
            {
                return(GetFunction(_doubleConverters));
            }
            if (type == typeof(ImmutableArray <string>))
            {
                return(GetFunction(_stringArrayConverters));
            }
            if (type == typeof(ImmutableArray <int>))
            {
                return(GetFunction(_integerArrayConverters));
            }
            if (type == typeof(ImmutableArray <double>))
            {
                return(GetFunction(_doubleArrayConverters));
            }

            throw new NotSupportedException($"Type {type} is not supported");

            Func <IActor, ITarget, CultureInfo, object> GetFunction <T>(IConverters <T> converters)
            {
                return((actor, container, culture) =>
                {
                    var relativeTarget = target.RelativeTo(container);
                    var question = uiStateAttribute.CreateQuestion(relativeTarget, converters, culture);
                    return actor.AsksFor(question);
                });
            }
        }
Exemplo n.º 2
0
        private static Func <IActor, ITarget, CultureInfo, object> ApplyGetConverter(ITarget target, Type type, UIStateAttribute uiStateAttribute)
        {
            if (type == typeof(int))
            {
                return(GetFunction(_integerConverters));
            }
            if (type == typeof(string))
            {
                return(GetFunction(_textConverters));
            }
            if (type == typeof(bool))
            {
                return(GetFunction(_booleanConverters));
            }
            if (type == typeof(DateTime))
            {
                return(GetFunction(_dateTimeConverters));
            }
            if (type == typeof(double))
            {
                return(GetFunction(_doubleConverters));
            }
            if (type == typeof(ImmutableArray <string>))
            {
                return(GetFunction(_stringArrayConverters));
            }
            if (type == typeof(ImmutableArray <int>))
            {
                return(GetFunction(_integerArrayConverters));
            }
            if (type == typeof(ImmutableArray <double>))
            {
                return(GetFunction(_doubleArrayConverters));
            }

            throw new NotSupportedException($"Type {type} is not supported");

            Func <IActor, ITarget, CultureInfo, object> GetFunction <T>(IConverters <T> converters)
            {
                return((actor, container, culture) =>
                {
                    var relativeTarget = target.RelativeTo(container);
                    var question = uiStateAttribute.CreateQuestion(relativeTarget, converters, culture);
                    return actor.AsksFor(question);
                });
            }
        }
Exemplo n.º 3
0
        private static Func <IActor, ITarget, CultureInfo, object> RetrieveValue(PropertyInfo pi, Func <string, ITarget> createTarget, string name, UIStateAttribute valueAttribute)
        {
            var target = createTarget(name ?? pi.Name);

            return(ApplyGetConverter(target, pi.PropertyType, valueAttribute));
        }
Exemplo n.º 4
0
        private static Func <IActor, ITarget, CultureInfo, object> RetrieveValue(PropertyInfo pi, By by, string name, UIStateAttribute valueAttribute)
        {
            var target = Target.The(name ?? pi.Name).LocatedBy(by);

            return(ApplyGetConverter(target, pi.PropertyType, valueAttribute));
        }