Ejemplo n.º 1
0
        private static void VerifyNullableEnumLongToUShort(El? value, bool useInterpreter)
        {
            Expression<Func<ushort>> e =
                Expression.Lambda<Func<ushort>>(
                    Expression.Convert(Expression.Constant(value, typeof(El?)), typeof(ushort)),
                    Enumerable.Empty<ParameterExpression>());
            Func<ushort> f = e.Compile(useInterpreter);

            if (value.HasValue)
                Assert.Equal((ushort)value.GetValueOrDefault(), f());
            else
                Assert.Throws<InvalidOperationException>(() => f());
        }
Ejemplo n.º 2
0
        private static void VerifyCheckedNullableEnumLongToSByte(El? value, bool useInterpreter)
        {
            Expression<Func<sbyte>> e =
                Expression.Lambda<Func<sbyte>>(
                    Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(sbyte)),
                    Enumerable.Empty<ParameterExpression>());
            Func<sbyte> f = e.Compile(useInterpreter);

            if (value.HasValue)
            {
                var unboxed = value.GetValueOrDefault();
                if ((long)unboxed < sbyte.MinValue | (long)unboxed > sbyte.MaxValue)
                    Assert.Throws<OverflowException>(() => f());
                else
                    Assert.Equal((sbyte)unboxed, f());
            }
            else
                Assert.Throws<InvalidOperationException>(() => f());
        }
Ejemplo n.º 3
0
        private static void VerifyCheckedNullableEnumLongToNullableULong(El? value, bool useInterpreter)
        {
            Expression<Func<ulong?>> e =
                Expression.Lambda<Func<ulong?>>(
                    Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(ulong?)),
                    Enumerable.Empty<ParameterExpression>());
            Func<ulong?> f = e.Compile(useInterpreter);

            if ((!value.HasValue))
                Assert.Null(f());
            else if (value.GetValueOrDefault() < 0)
                Assert.Throws<OverflowException>(() => f());
            else
                Assert.Equal((ulong?)value.GetValueOrDefault(), f());
        }
Ejemplo n.º 4
0
        private static void VerifyCheckedNullableEnumLongToEnum(El? value, bool useInterpreter)
        {
            Expression<Func<E>> e =
                Expression.Lambda<Func<E>>(
                    Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(E)),
                    Enumerable.Empty<ParameterExpression>());
            Func<E> f = e.Compile(useInterpreter);

            if (value.HasValue)
            {
                if ((long)value.GetValueOrDefault() < int.MinValue || (long)value.GetValueOrDefault() > int.MaxValue)
                    Assert.Throws<OverflowException>(() => f());
                else
                    Assert.Equal((E)value.GetValueOrDefault(), f());
            }
            else
                Assert.Throws<InvalidOperationException>(() => f());
        }