Exemple #1
0
        /// <inheritdoc />
        public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo)
        {
            if (string.IsNullOrEmpty(dimensionInfo))
            {
                throw new CSReaderException(
                          $"ERROR: NO DIMENSION INFO FOUND EXPECTED: DICTIONARY<GENERIC_TYPE_INFO1, GENERIC_TYPE_INFO2>(count) -> DICTIONARY{genericTypeInfo}{dimensionInfo}");
            }
            if (string.IsNullOrEmpty(genericTypeInfo))
            {
                throw new CSReaderException(
                          "ERROR: NO GENERIC TYPE INFO DEFINED -> DICTIONARY<GENERIC_TYPE_INFO1, GENERIC_TYPE_INFO2>");
            }

            genericTypeInfo.GetKeyValueInnerType(out string kbti, out string vbti, out string vgti);

            if (!ContentSerializer.s_types.TryGetValue(kbti, out IType itk) || !itk.IsPrimitive)
            {
                throw new NotSupportedException($"ERROR: INVALID KEY TYPE FOUND IN -> '{genericTypeInfo}'");
            }

            Type valueType;
            Func <CSStreamReader, string, object> readCallback;

            if (ContentSerializer.s_types.TryGetValue(vbti, out IType it))
            {
                valueType    = it.CreateType(vgti);
                readCallback = (s, d) =>
                {
                    return(it.Read(stream, string.Empty, vgti, d));
                };
            }
            else
            {
                valueType    = vbti.CreateType();
                readCallback = (s, d) =>
                {
                    return(ContentSerializer.Read(stream, valueType, string.Empty));
                };
            }

            int count = GetDictionaryCount(dimensionInfo);

            Type   dic = BaseType.MakeGenericType(itk.CreateType(string.Empty), valueType);
            object obj = System.Activator.CreateInstance(dic, count);

            AddDictionaryContent(stream, readCallback, (dynamic)obj, count);
            stream.ReadTag($"/{key}");
            return(obj);
        }
Exemple #2
0
        /// <inheritdoc />
        public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo)
        {
            if (string.IsNullOrEmpty(dimensionInfo))
            {
                throw new CSReaderException(
                          $"ERROR: NO DIMENSION INFO FOUND EXPECTED: LIST<GENERIC_TYPE_INFO>(count) -> LIST{genericTypeInfo}{dimensionInfo}");
            }
            if (string.IsNullOrEmpty(genericTypeInfo))
            {
                throw new CSReaderException("ERROR: NO GENERIC TYPE INFO DEFINED -> LIST<GENERIC_TYPE_INFO>");
            }

            genericTypeInfo.GetInnerType(out string bti, out string gti);

            Type elementType;
            Func <CSStreamReader, string, object> readCallback;

            if (ContentSerializer.s_types.TryGetValue(bti, out IType it))
            {
                elementType  = it.CreateType(gti);
                readCallback = (s, d) =>
                {
                    return(it.Read(stream, string.Empty, gti, d));
                };
            }
            else
            {
                elementType  = bti.CreateType();
                readCallback = (s, d) =>
                {
                    return(ContentSerializer.Read(stream, elementType, string.Empty));
                };
            }

            int count = GetListCount(dimensionInfo);

            Type   list = BaseType.MakeGenericType(elementType);
            object obj  = System.Activator.CreateInstance(list, count);

            AddListContent(stream, readCallback, (dynamic)obj, count);
            stream.ReadTag($"/{key}");
            return(obj);
        }
Exemple #3
0
        /// <inheritdoc />
        public object Read(CSStreamReader stream, string key, string genericTypeInfo, string dimensionInfo)
        {
            if (string.IsNullOrEmpty(dimensionInfo))
            {
                throw new CSReaderException(
                          $"ERROR: NO DIMENSION INFO FOUND EXPECTED: ARRAY<GENERIC_TYPE_INFO>(d1,d2,...,dx) -> ARRAY{genericTypeInfo}{dimensionInfo}");
            }
            if (string.IsNullOrEmpty(genericTypeInfo))
            {
                throw new CSReaderException("ERROR: NO GENERIC TYPE INFO DEFINED -> ARRAY<GENERIC_TYPE_INFO>");
            }

            genericTypeInfo.GetInnerType(out string bti, out string gti);

            Type elementType;
            Func <CSStreamReader, string, object> readCallback;

            if (ContentSerializer.s_types.TryGetValue(bti, out IType it))
            {
                elementType  = it.CreateType(gti);
                readCallback = (s, d) =>
                {
                    return(it.Read(stream, string.Empty, gti, d));
                };
            }
            else
            {
                elementType  = bti.CreateType();
                readCallback = (s, d) =>
                {
                    return(ContentSerializer.Read(stream, elementType, string.Empty));
                };
            }

            int[] dimensions = GetArrayDimensionInfo(dimensionInfo);
            Array arr        = Array.CreateInstance(elementType, dimensions);

            AddArrayContent(stream, readCallback, arr, dimensions, new int[dimensions.Length], 0);
            stream.ReadTag($"/{key}");

            return(arr);
        }