コード例 #1
0
        public void SlimInfoOf_ArgumentChecking()
        {
#pragma warning disable IDE0034 // Simplify 'default' expression (illustrative of method signature)
            AssertEx.ThrowsException <ArgumentNullException>(() => SlimReflectionHelpers.InfoOf(default(Expression)), ex => Assert.AreEqual("expression", ex.ParamName));
            AssertEx.ThrowsException <ArgumentNullException>(() => SlimReflectionHelpers.InfoOf(default(Expression <Action>)), ex => Assert.AreEqual("expression", ex.ParamName));
            AssertEx.ThrowsException <ArgumentNullException>(() => SlimReflectionHelpers.InfoOf(default(Expression <Action <int> >)), ex => Assert.AreEqual("expression", ex.ParamName));
            AssertEx.ThrowsException <ArgumentNullException>(() => SlimReflectionHelpers.InfoOf(default(Expression <Func <int> >)), ex => Assert.AreEqual("expression", ex.ParamName));
            AssertEx.ThrowsException <ArgumentNullException>(() => SlimReflectionHelpers.InfoOf(default(Expression <Func <int, int> >)), ex => Assert.AreEqual("expression", ex.ParamName));
#pragma warning restore IDE0034 // Simplify 'default' expression
        }
コード例 #2
0
 public void SlimInfoOf_New_ConstructorInfo()
 {
     AssertAreSame(typeof(Exception).GetConstructor(new[] { typeof(string) }), SlimReflectionHelpers.InfoOf((string s) => new Exception(s)));
 }
コード例 #3
0
 public void SlimInfoOf_Member_PropertyInfo()
 {
     AssertAreSame(typeof(Console).GetProperty("ForegroundColor"), SlimReflectionHelpers.InfoOf(() => Console.ForegroundColor));
 }
コード例 #4
0
        public void SlimInfoOf_Binary_Add_MethodInfo()
        {
            var add = typeof(DateTime).GetMethods().Single(m => m.Name == "op_Addition" && m.GetParameters()[0].ParameterType == typeof(DateTime) && m.GetParameters()[1].ParameterType == typeof(TimeSpan) && m.ReturnType == typeof(DateTime));

            AssertAreSame(add, SlimReflectionHelpers.InfoOf <DateTime, DateTime>(d => d + default(TimeSpan)));
        }
コード例 #5
0
        public void SlimInfoOf_Unary_Negate_MethodInfo()
        {
            var negate = typeof(TimeSpan).GetMethods().Single(m => m.Name == "op_UnaryNegation" && m.GetParameters()[0].ParameterType == typeof(TimeSpan) && m.ReturnType == typeof(TimeSpan));

            AssertAreSame(negate, SlimReflectionHelpers.InfoOf <TimeSpan, TimeSpan>(t => - t));
        }
コード例 #6
0
        public void SlimInfoOf_Unary_Convert_MethodInfo()
        {
            var convert = typeof(DateTimeOffset).GetMethods().Single(m => m.Name == "op_Implicit" && m.GetParameters()[0].ParameterType == typeof(DateTime) && m.ReturnType == typeof(DateTimeOffset));

            AssertAreSame(convert, SlimReflectionHelpers.InfoOf <DateTime, DateTimeOffset>(dt => dt));
        }
コード例 #7
0
 public void SlimInfoOf_MethodCall_MethodInfo2()
 {
     AssertAreSame(typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }), SlimReflectionHelpers.InfoOf((string s) => Console.WriteLine(s)));
 }
コード例 #8
0
 public void SlimInfoOf_MethodCall_MethodInfo1()
 {
     AssertAreSame(typeof(Console).GetMethod("WriteLine", Type.EmptyTypes), SlimReflectionHelpers.InfoOf(() => Console.WriteLine()));
 }
コード例 #9
0
 public void SlimInfoOf_NoReflectionInfo()
 {
     Assert.ThrowsException <NotSupportedException>(() => SlimReflectionHelpers.InfoOf(Expression.Constant(42)));
     Assert.ThrowsException <NotSupportedException>(() => SlimReflectionHelpers.InfoOf(Expression.Negate(Expression.Constant(42))));
     Assert.ThrowsException <NotSupportedException>(() => SlimReflectionHelpers.InfoOf(Expression.Add(Expression.Constant(1), Expression.Constant(2))));
 }