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 }
public void SlimInfoOf_New_ConstructorInfo() { AssertAreSame(typeof(Exception).GetConstructor(new[] { typeof(string) }), SlimReflectionHelpers.InfoOf((string s) => new Exception(s))); }
public void SlimInfoOf_Member_PropertyInfo() { AssertAreSame(typeof(Console).GetProperty("ForegroundColor"), SlimReflectionHelpers.InfoOf(() => Console.ForegroundColor)); }
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))); }
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)); }
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)); }
public void SlimInfoOf_MethodCall_MethodInfo2() { AssertAreSame(typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }), SlimReflectionHelpers.InfoOf((string s) => Console.WriteLine(s))); }
public void SlimInfoOf_MethodCall_MethodInfo1() { AssertAreSame(typeof(Console).GetMethod("WriteLine", Type.EmptyTypes), SlimReflectionHelpers.InfoOf(() => Console.WriteLine())); }
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)))); }