public void MemberInfoSlimVisitor_VisitSimpleMethod_AreSame() { var visitor = new MemberInfoSlimVisitor(); var simple = SlimType.GetSimpleMethod("Foo", EmptyReadOnlyCollection <TypeSlim> .Instance, returnType: null); Assert.AreSame(simple, visitor.Visit(simple)); }
public void SimpleMethodInfoSlimBase_ArgumentChecks() { AssertEx.ThrowsException <ArgumentNullException>(() => TypeSlimExtensions.GetSimpleMethod(type: null, "bar", parameterTypes: null, returnType: null), ex => Assert.AreEqual("type", ex.ParamName)); AssertEx.ThrowsException <ArgumentNullException>(() => SlimType.GetSimpleMethod(name: null, parameterTypes: null, returnType: null), ex => Assert.AreEqual("name", ex.ParamName)); AssertEx.ThrowsException <ArgumentException>(() => SlimType.GetSimpleMethod("", parameterTypes: null, returnType: null), ex => Assert.AreEqual("name", ex.ParamName)); AssertEx.ThrowsException <ArgumentNullException>(() => SlimType.GetSimpleMethod("foo", parameterTypes: null, returnType: null), ex => Assert.AreEqual("parameterTypes", ex.ParamName)); var m = SlimType.GetSimpleMethod("foo", Empty, returnType: null); }
public void ExpressionSlim_Update_Tests() { var boolSlim = new TypeToTypeSlimConverter().Visit(typeof(bool)); var intExpr1 = ExpressionSlim.Parameter(SlimType); var intExpr2 = ExpressionSlim.Parameter(SlimType); var intExpr3 = ExpressionSlim.Parameter(SlimType); var boolExpr1 = ExpressionSlim.Parameter(boolSlim); var boolExpr2 = ExpressionSlim.Parameter(boolSlim); var prop = SlimType.GetProperty("Foo", propertyType: null, EmptyReadOnlyCollection <TypeSlim> .Instance, canWrite: true); var elementInits = new ElementInitSlim[] { new ElementInitSlim(addMethod: null, arguments: null) }.ToReadOnly(); var method = SlimType.GetSimpleMethod("Foo", EmptyReadOnlyCollection <TypeSlim> .Instance, returnType: null); var b = ExpressionSlim.Add(intExpr1, intExpr2); Assert.AreNotSame(b, b.Update(intExpr1, conversion: null, intExpr3)); Assert.AreNotSame(b, b.Update(intExpr3, conversion: null, intExpr2)); var c = ExpressionSlim.Condition(boolExpr1, intExpr1, intExpr2); Assert.AreNotSame(c, c.Update(boolExpr2, intExpr1, intExpr2)); Assert.AreNotSame(c, c.Update(boolExpr1, intExpr2, intExpr3)); Assert.AreNotSame(c, c.Update(boolExpr1, intExpr1, intExpr3)); var i = ExpressionSlim.MakeIndex(intExpr1, prop, new ExpressionSlim[] { intExpr2 }.ToReadOnly()); Assert.AreNotSame(i, i.Update(intExpr2, new ExpressionSlim[] { intExpr2 }.ToReadOnly())); Assert.AreNotSame(i, i.Update(intExpr1, new ExpressionSlim[] { intExpr3 }.ToReadOnly())); var inv = ExpressionSlim.Invoke(intExpr1, new[] { intExpr2 }); Assert.AreNotSame(inv, inv.Update(intExpr2, new ExpressionSlim[] { intExpr2 }.ToReadOnly())); Assert.AreNotSame(inv, inv.Update(intExpr1, new ExpressionSlim[] { intExpr3 }.ToReadOnly())); var l = ExpressionSlim.Lambda(intExpr1); Assert.AreNotSame(l, l.Update(intExpr2, EmptyReadOnlyCollection <ParameterExpressionSlim> .Instance)); Assert.AreNotSame(l, l.Update(intExpr1, new ParameterExpressionSlim[] { ExpressionSlim.Parameter(SlimType) }.ToReadOnly())); var li = ExpressionSlim.ListInit(ExpressionSlim.New(SlimType)); Assert.AreNotSame(li, li.Update(ExpressionSlim.New(boolSlim), elementInits)); Assert.AreNotSame(li, li.Update(ExpressionSlim.New(SlimType), elementInits)); var ma = ExpressionSlim.Bind(prop, intExpr1); Assert.AreNotSame(ma, ma.Update(intExpr2)); var macc = ExpressionSlim.MakeMemberAccess(instance: null, prop); Assert.AreNotSame(macc, macc.Update(intExpr1)); var ml = ExpressionSlim.ListBind(prop); Assert.AreNotSame(ml, ml.Update(elementInits)); var mm = ExpressionSlim.MemberBind(prop); Assert.AreNotSame(mm, mm.Update(new MemberBindingSlim[] { ExpressionSlim.Bind(prop, intExpr1) }.ToReadOnly())); var m = ExpressionSlim.Call(method); Assert.AreNotSame(m, m.Update(intExpr1, new ExpressionSlim[] { intExpr2 }.ToReadOnly())); Assert.AreNotSame(m, m.Update(@object: null, new ExpressionSlim[] { intExpr2 }.ToReadOnly())); var na = ExpressionSlim.NewArrayInit(SlimType); Assert.AreNotSame(na, na.Update(new ExpressionSlim[] { intExpr1 }.ToReadOnly())); var nb = ExpressionSlim.NewArrayBounds(SlimType, intExpr1); Assert.AreNotSame(nb, nb.Update(new ExpressionSlim[] { intExpr2 }.ToReadOnly())); var ctor = SlimType.GetConstructor(new TypeSlim[] { SlimType }.ToReadOnly()); var n = ExpressionSlim.New(ctor, ExpressionSlim.Parameter(SlimType)); Assert.AreNotSame(n, n.Update(new ExpressionSlim[] { ExpressionSlim.Default(SlimType) }.ToReadOnly())); var t = ExpressionSlim.TypeIs(intExpr1, SlimType); Assert.AreNotSame(t, t.Update(intExpr2)); var u = ExpressionSlim.Not(boolExpr1); Assert.AreNotSame(u, u.Update(boolExpr2)); }