Esempio n. 1
0
        /// <summary>
        /// 数组解析
        /// </summary>
        /// <param name="deSerializer">XML解析器</param>
        /// <param name="values">目标数据</param>
        /// <returns>数据数量,-1表示失败</returns>
        internal static int ArrayIndex(XmlDeSerializer deSerializer, ref T[] values)
        {
            if (values == null)
            {
                values = EmptyArray <T> .Array;
            }
            string arrayItemName = deSerializer.ArrayItemName;

            AutoCSer.Memory.Pointer name = default(AutoCSer.Memory.Pointer);
            int  index    = 0;
            byte isTagEnd = 0;

            fixed(char *itemFixed = arrayItemName)
            {
                do
                {
                    if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                    {
                        break;
                    }
                    if (isTagEnd == 0)
                    {
                        if (arrayItemName.Length != name.ByteSize || !AutoCSer.Memory.Common.SimpleEqualNotNull((byte *)itemFixed, name.Byte, name.ByteSize << 1))
                        {
                            deSerializer.State = DeSerializeState.NotArrayItem;
                            return(-1);
                        }
                        if (index == values.Length)
                        {
                            T value = default(T);
                            if (deSerializer.IsArrayItem(itemFixed, arrayItemName.Length) != 0)
                            {
                                DeSerialize(deSerializer, ref value);
                                if (deSerializer.State != DeSerializeState.Success)
                                {
                                    return(-1);
                                }
                                if (deSerializer.CheckNameEnd(itemFixed, name.ByteSize) == 0)
                                {
                                    break;
                                }
                            }
                            values          = values.copyNew(index == 0 ? deSerializer.Config.NewArraySize : (index << 1));
                            values[index++] = value;
                        }
                        else
                        {
                            if (deSerializer.IsArrayItem(itemFixed, arrayItemName.Length) != 0)
                            {
                                DeSerialize(deSerializer, ref values[index]);
                                if (deSerializer.State != DeSerializeState.Success)
                                {
                                    return(-1);
                                }
                                if (deSerializer.CheckNameEnd(itemFixed, name.ByteSize) == 0)
                                {
                                    break;
                                }
                            }
                            ++index;
                        }
                    }
                    else
                    {
                        if (index == values.Length)
                        {
                            values = values.copyNew(index == 0 ? deSerializer.Config.NewArraySize : (index << 1));
                        }
                        values[index++] = default(T);
                    }
                }while (true);
            }

            return(deSerializer.State == DeSerializeState.Success ? index : -1);
        }