Ejemplo n.º 1
0
        public static BoolControlOption <T> Create <T>(
            T[] controls, string name, Expression <Func <T, bool> > propertyExpression,
            bool negated = false)
        {
            var property = propertyExpression.TryGetProperty();

            if (property == null)
            {
                throw new ArgumentException("propertyName");
            }

            BoolControlOption <T> option;

            if (negated)
            {
                option = new BoolControlOption <T>(
                    controls,
                    name,
                    c => !(bool)property.GetValue(c, null),
                    (c, value) => property.SetValue(c, !value, null));
            }
            else
            {
                option = new BoolControlOption <T>(
                    controls,
                    name,
                    c => (bool)property.GetValue(c, null),
                    (c, value) => property.SetValue(c, value, null));
            }

            return(option);
        }
Ejemplo n.º 2
0
        public static BoolControlOption <T> Create <T, TValue>(
            T[] controls,
            string name,
            Expression <Func <T, TValue> > propertyExpression,
            TValue trueValue,
            TValue falseValue)
        {
            var property = typeof(T).GetProperty(((MemberExpression)propertyExpression.Body).Member.Name);

            if (property == null)
            {
                throw new ArgumentException("propertyName");
            }

            var option = new BoolControlOption <T>(
                controls,
                name,
                c => ((TValue)property.GetValue(c, null)).Equals(trueValue),
                (c, v) => property.SetValue(c, v ? trueValue : falseValue, null));

            return(option);
        }