Exemple #1
0
        public void TestCreateConstructor1()
        {
            Func0 create = Accelerator.CreateStandardConstructor(typeof(int));

            Assert.IsNotNull(create);
            Assert.IsTrue(create() is int);
        }
        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;
                }
            });
        }
Exemple #3
0
        public void TestCreateConstructor3()
        {
            Assert.IsNotNull(default(ExampleStruct1));
            Func0 create = Accelerator.CreateStandardConstructor(typeof(ExampleStruct1));

            Assert.IsNotNull(create);
            Assert.IsTrue(create() is ExampleStruct1);
        }
Exemple #4
0
        public void TestCreateConstructor2()
        {
            Func0 create = Accelerator.CreateStandardConstructor(typeof(int[]));

            Assert.IsNotNull(create);
            int[] a = (int[])create();
            Assert.AreEqual(0, a.Length);
        }
        static DeserializerDelegate RetrieveDeserializer2_object(Type type)
        {
            Func0 create = Accelerator.CreateStandardConstructor(type);
            var   cache  = JsonTypeCache.Instance.RetrieveCacheEntry(type);

            return((JsonDeserializer deserializer, JsonTokenizer tokenizer, out object value) =>
            {
                if (tokenizer.SpecialChar == '{')
                {
                    value = create();
                    deserializer.DeserializeObject(tokenizer, value, cache);
                    return true;
                }
                else
                {
                    tokenizer.SkipValueBody();
                    value = null;
                    return false;
                }
            });
        }
Exemple #6
0
        public static MeasuringData[] CompareNewGuid_AcceleratorReflection()
        {
            Type  type   = typeof(Guid);
            Func0 create = Accelerator.CreateStandardConstructor(type);

            Action a1 = () =>
            {
                for (int z = 0; z < c_RepetitionCount; z++)
                {
                    create();
                }
            };

            Action a2 = () =>
            {
                for (int z = 0; z < c_RepetitionCount; z++)
                {
                    Activator.CreateInstance(type);
                }
            };

            return(TestEnvironment.Measure(a1, a2));
        }