Exemplo n.º 1
0
        // Called via reflection
        private static object CallNullSafePropertyGetterByReference <TDeclaringType, TValue>(
            ByRefFunc <TDeclaringType, TValue> getter,
            object target)
        {
            if (target == null)
            {
                return(null);
            }

            var unboxed = (TDeclaringType)target;

            return(getter(ref unboxed));
        }
Exemplo n.º 2
0
        public void CanUseAsLambdaByRefParameter_Bool(bool useInterpreter)
        {
            ParameterExpression param = Expression.Parameter(typeof(bool).MakeByRefType());
            ByRefFunc <bool>    f     = Expression.Lambda <ByRefFunc <bool> >(
                Expression.ExclusiveOrAssign(param, Expression.Constant(true)),
                param
                ).Compile(useInterpreter);

            bool b1 = false;

            f(ref b1);
            Assert.Equal(false ^ true, b1);

            bool b2 = true;

            f(ref b2);
            Assert.Equal(true ^ true, b2);
        }
Exemplo n.º 3
0
        private static object CallPropertyGetterByReference <TDeclaringType, TValue>(ByRefFunc <TDeclaringType, TValue> getter, object @this)
        {
            TDeclaringType unboxed = (TDeclaringType)@this;

            return(getter(ref unboxed));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calls the property getter for the given value type, called by reference.
        /// </summary>
        /// <typeparam name="TDeclaringType">The reference type.</typeparam>
        /// <typeparam name="TValue">The value type.</typeparam>
        /// <param name="getter">The getter delegate</param>
        /// <param name="target">The target container.</param>
        /// <returns>The property value.</returns>
        private static object CallPropertyGetterByReference <TDeclaringType, TValue>(ByRefFunc <TDeclaringType, TValue> getter, object target)
        {
            var unboxed = (TDeclaringType)target;

            return(getter(ref unboxed));
        }