public void TestCreateFunction1c() { string n = nameof(ExampleClass2.AppendTextAndGet); MethodInfo m = typeof(ExampleClass2).GetMethod(n, Type.EmptyTypes); Func1 appendAndGet = Accelerator.CreateFunction1(m); var o = new ExampleClass2(); Assert.AreEqual(null, o.Text); o.Text = "ABC"; Assert.AreEqual("ABCtext", o.AppendTextAndGet()); Assert.AreEqual("ABCtext", o.Text); Assert.AreEqual("ABCtexttext", appendAndGet(o)); Assert.AreEqual("ABCtexttext", o.Text); }
public JsonTypeMemberEntry(string jsonName, Type propertyType, MethodInfo getMethod, MethodInfo setMethod) { IsEscapingRequired = JsonWriter.IsEscapingRequired(jsonName); MemberType = propertyType; if (getMethod != null) { ReadValue = Accelerator.CreateFunction1(getMethod); } if (setMethod != null) { WriteValue = Accelerator.CreateAction2(setMethod); } }
public void TestAccessValueProperty() { string n = nameof(ClassWithProperties.Text); PropertyInfo pi = typeof(ClassWithProperties).GetProperty(n); Func1 getText = Accelerator.CreateFunction1(pi.GetMethod); Action2 setText = Accelerator.CreateAction2(pi.SetMethod); var o = new ClassWithProperties("ABC"); Assert.AreEqual("ABC", o.Text); Assert.AreEqual("ABC", getText(o)); setText(o, "XYZ"); Assert.AreEqual("XYZ", o.Text); Assert.AreEqual("XYZ", getText(o)); }
public void TestAccessClassProperty() { string n = nameof(ClassWithProperties.Value); PropertyInfo pi = typeof(ClassWithProperties).GetProperty(n); Func1 getValue = Accelerator.CreateFunction1(pi.GetMethod); Action2 setValue = Accelerator.CreateAction2(pi.SetMethod); var o = new ClassWithProperties(123); Assert.AreEqual(123, o.Value); Assert.AreEqual(123, getValue(o)); setValue(o, 456); Assert.AreEqual(456, o.Value); Assert.AreEqual(456, getValue(o)); }
public void TestCreateFunction1a() { string n = nameof(ExampleClass1.IncrementAndGet); MethodInfo m = typeof(ExampleClass1).GetMethod(n, Type.EmptyTypes); Func1 incAndGet = Accelerator.CreateFunction1(m); var o = new ExampleClass1(); Assert.AreEqual(0, o.Value); Assert.AreEqual(1, o.IncrementAndGet()); Assert.AreEqual(1, o.Value); Assert.AreEqual(2, (int)incAndGet(o)); Assert.AreEqual(2, o.Value); Assert.AreEqual(3, (int)incAndGet(o)); Assert.AreEqual(4, (int)incAndGet(o)); Assert.AreEqual(4, o.Value); }
public void TestCreateFunction1d() { string n = nameof(ExampleStruct2.AppendTextAndGet); MethodInfo m = typeof(ExampleStruct2).GetMethod(n, Type.EmptyTypes); Func1 appendAndGet = Accelerator.CreateFunction1(m); var unboxed = new ExampleStruct2(); Assert.AreEqual(null, unboxed.Text); unboxed.Text = "ABC"; Assert.AreEqual("ABCtext", unboxed.AppendTextAndGet()); Assert.AreEqual("ABCtext", unboxed.Text); object boxed = unboxed; Assert.AreEqual("ABCtexttext", appendAndGet(boxed)); Assert.AreEqual("ABCtexttext", ((ExampleStruct2)boxed).Text); }
public void TestCreateFunction1b() { string n = nameof(ExampleStruct1.IncrementAndGet); MethodInfo m = typeof(ExampleStruct1).GetMethod(n, Type.EmptyTypes); Func1 incAndGet = Accelerator.CreateFunction1(m); var unboxed = new ExampleStruct1(); Assert.AreEqual(0, unboxed.Value); Assert.AreEqual(1, unboxed.IncrementAndGet()); Assert.AreEqual(1, unboxed.Value); object boxed = unboxed; Assert.AreEqual(2, (int)incAndGet(boxed)); Assert.AreEqual(2, ((ExampleStruct1)boxed).Value); Assert.AreEqual(3, (int)incAndGet(boxed)); Assert.AreEqual(4, (int)incAndGet(boxed)); Assert.AreEqual(4, ((ExampleStruct1)boxed).Value); }