Exemplo n.º 1
0
        private static LambdaExpression GenerateGetterLambda <TInterface, TState, TArg>(PropertyInfo stateProperty)
        {
            var ctxParam            = Expression.Parameter(typeof(IContext <TInterface, TState>), "ctx");
            var stateGetter         = Expression.Property(ctxParam, PropertyReflector <IContext <TInterface, TState> > .FromGetter(s => s.State));
            var statePropertyGetter = Expression.Property(stateGetter, stateProperty);

            return(Expression.Lambda <Func <IContext <TInterface, TState>, TArg> >(statePropertyGetter, ctxParam));
        }
Exemplo n.º 2
0
        private static LambdaExpression GenerateSetterLambda <TInterface, TState, TArg>(PropertyInfo stateProperty)
        {
            var setMethod              = stateProperty.GetSetMethod();
            var ctxParam               = Expression.Parameter(typeof(IContext <TInterface, TState>), "ctx");
            var argParam               = Expression.Parameter(typeof(TArg), "value");
            var stateGetter            = Expression.Property(ctxParam, PropertyReflector <IContext <TInterface, TState> > .FromGetter(s => s.State));
            var statePropertySetMethod = Expression.Call(stateGetter, setMethod, argParam);

            return(Expression.Lambda <Action <IContext <TInterface, TState>, TArg> >(statePropertySetMethod, ctxParam, argParam));
        }
Exemplo n.º 3
0
        public void Should_find_property_based_on_getter_method()
        {
            PropertyInfo propertyInfo = typeof(SomeClass).GetProperty("GetterOnly");

            Assert.That(PropertyReflector <SomeClass> .FromGetter(c => c.GetterOnly), Is.EqualTo(propertyInfo));
        }