static DeserializerDelegate RetrieveDeserializer2_IList(Type type, Type ga0)
        {
            Func0 create = Accelerator.CreateStandardConstructor(type);

            MethodInfo m = type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { ga0 }, null);

            if (m == null)
            {
                throw new InvalidOperationException();
            }

            Action2 a = Accelerator.CreateAction2(m);

            return((JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) =>
            {
                if (tokenizer.BeginReadArray())
                {
                    object list = create();
                    deserializer.DeserializeCollection(tokenizer, ga0, x => a(list, x));
                    value = list;
                    return true;
                }
                else
                {
                    value = null;
                    return false;
                }
            });
        }
        public void TestCreateAction2a()
        {
            string  n   = nameof(ExampleClass1.Increment);
            Action2 inc = Accelerator.CreateAction2(typeof(ExampleClass1).GetMethod(n, new[] { typeof(int) }));

            var o = new ExampleClass1();

            o.Increment(1);
            Assert.AreEqual(1, o.Value);
            inc(o, 3);
            Assert.AreEqual(4, o.Value);
            inc(o, 11);
            Assert.AreEqual(15, o.Value);
        }
        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);
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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 TestCreateAction2d()
        {
            string  n   = nameof(ExampleStruct2.Increment);
            Action2 inc = Accelerator.CreateAction2(typeof(ExampleStruct2).GetMethod(n, new[] { typeof(int) }));

            var unboxed = new ExampleStruct2();

            unboxed.Increment(1);
            Assert.AreEqual(1, unboxed.Value);

            IExample boxed = unboxed;

            inc(boxed, 3);
            Assert.AreEqual(4, boxed.Value);
            inc(boxed, 11);
            Assert.AreEqual(15, boxed.Value);
        }