Ejemplo n.º 1
0
        public static void InitAot <T>()
        {
            var hold = DeserializeBuiltin <T> .Parse;

            hold = DeserializeArray <T[], TSerializer> .Parse;
            DeserializeType <TSerializer> .ExtractType(null);

            DeserializeArrayWithElements <T, TSerializer> .ParseGenericArray(null, null);

            DeserializeCollection <TSerializer> .ParseCollection <T>(null, null, null);

            DeserializeListWithElements <T, TSerializer> .ParseGenericList(null, null, null);
        }
Ejemplo n.º 2
0
        public static ParseStringSegmentDelegate GetParseStringSegmentFn()
        {
            var enumerableInterface = typeof(T).GetTypeWithGenericInterfaceOf(typeof(IEnumerable <>));

            if (enumerableInterface == null)
            {
                throw new ArgumentException($"Type {typeof(T).FullName} is not of type IEnumerable<>");
            }

            //optimized access for regularly used types
            if (typeof(T) == typeof(IEnumerable <string>))
            {
                return(DeserializeListWithElements <TSerializer> .ParseStringList);
            }

            if (typeof(T) == typeof(IEnumerable <int>))
            {
                return(DeserializeListWithElements <TSerializer> .ParseIntList);
            }

            var elementType = enumerableInterface.GetGenericArguments()[0];

            var supportedTypeParseMethod = DeserializeListWithElements <TSerializer> .Serializer.GetParseStringSegmentFn(elementType);

            if (supportedTypeParseMethod != null)
            {
                const Type createListTypeWithNull = null; //Use conversions outside this class. see: Queue

                var parseFn = DeserializeListWithElements <TSerializer> .GetListTypeParseStringSegmentFn(
                    createListTypeWithNull, elementType, supportedTypeParseMethod);

                return(value => parseFn(value, createListTypeWithNull, supportedTypeParseMethod));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static ParseStringSegmentDelegate GetParseStringSegmentFn()
        {
            var listInterface = typeof(T).GetTypeWithGenericInterfaceOf(typeof(IList <>));

            if (listInterface == null)
            {
                throw new ArgumentException($"Type {typeof(T).FullName} is not of type IList<>");
            }

            //optimized access for regularly used types
            if (typeof(T) == typeof(List <string>))
            {
                return(DeserializeListWithElements <TSerializer> .ParseStringList);
            }

            if (typeof(T) == typeof(List <int>))
            {
                return(DeserializeListWithElements <TSerializer> .ParseIntList);
            }

            var elementType = listInterface.GetGenericArguments()[0];

            var supportedTypeParseMethod = DeserializeListWithElements <TSerializer> .Serializer.GetParseStringSegmentFn(elementType);

            if (supportedTypeParseMethod != null)
            {
                var createListType = typeof(T).HasAnyTypeDefinitionsOf(typeof(List <>), typeof(IList <>))
                    ? null : typeof(T);

                var parseFn = DeserializeListWithElements <TSerializer> .GetListTypeParseStringSegmentFn(createListType, elementType, supportedTypeParseMethod);

                return(value => parseFn(value, createListType, supportedTypeParseMethod));
            }

            return(null);
        }