Пример #1
0
 public static StringCollection ParseStringCollection <TS>(string value) where TS : ITypeSerializer
 {
     if ((value = DeserializeListWithElements <TS> .StripList(value)) == null)
     {
         return(null);
     }
     return(value == String.Empty
            ? new StringCollection()
            : ToStringCollection(DeserializeListWithElements <TSerializer> .ParseStringList(value)));
 }
Пример #2
0
        public static void InitAot <T>()
        {
            var hold = DeserializeBuiltin <T> .Parse;

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

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

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

            DeserializeListWithElements <T, TSerializer> .ParseGenericList(default(ReadOnlySpan <char>), null, null);
        }
Пример #3
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);
        }
        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);
        }
        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);
        }