示例#1
0
        /// <summary>
        /// 数据成员解析
        /// </summary>
        /// <param name="deSerializer">XML解析器</param>
        /// <param name="value">目标数据</param>
        internal static void DeSerializeMembers(XmlDeSerializer deSerializer, ref T value)
        {
            byte *            names     = memberNames.Byte;
            DeSerializeConfig config    = deSerializer.Config;
            MemberMap         memberMap = deSerializer.MemberMap;
            int index = 0;

            if (memberMap == null)
            {
                while (deSerializer.IsName(names, ref index))
                {
                    if (index == -1)
                    {
                        return;
                    }
                    memberDeSerializers[index].Call(deSerializer, ref value);
                    if (deSerializer.State != DeSerializeState.Success)
                    {
                        return;
                    }
                    if (deSerializer.IsNameEnd(names) == 0)
                    {
                        if (deSerializer.CheckNameEnd((char *)(names + (sizeof(short) + sizeof(char))), (*(short *)names >> 1) - 2) == 0)
                        {
                            return;
                        }
                        break;
                    }
                    ++index;
                    names += *(short *)names + sizeof(short);
                }
                AutoCSer.StateSearcher.CharSearcher searcher = new AutoCSer.StateSearcher.CharSearcher(memberSearcher);
                AutoCSer.Memory.Pointer             name     = default(AutoCSer.Memory.Pointer);
                byte isTagEnd = 0;
                if (onUnknownName == null)
                {
                    do
                    {
                        if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                        {
                            return;
                        }
                        if (isTagEnd == 0)
                        {
                            if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                            {
                                if (deSerializer.IgnoreValue() == 0)
                                {
                                    return;
                                }
                            }
                            else if (memberDeSerializers[index].Call(deSerializer, ref value) == 0)
                            {
                                return;
                            }
                            if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                            {
                                return;
                            }
                        }
                    }while (true);
                }
                else
                {
                    do
                    {
                        if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                        {
                            return;
                        }
                        if (isTagEnd == 0)
                        {
                            if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                            {
                                name.ByteSize <<= 1;
                                if (onUnknownName(deSerializer, ref value, ref name))
                                {
                                    if (deSerializer.State != DeSerializeState.Success)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    if (deSerializer.State == DeSerializeState.Success)
                                    {
                                        deSerializer.State = DeSerializeState.UnknownNameError;
                                    }
                                    return;
                                }
                            }
                            else if (memberDeSerializers[index].Call(deSerializer, ref value) == 0)
                            {
                                return;
                            }
                            if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                            {
                                return;
                            }
                        }
                    }while (true);
                }
            }
            else if (object.ReferenceEquals(memberMap.Type, MemberMap <T> .MemberMapType))
            {
                memberMap.Empty();
                deSerializer.MemberMap = null;
                while (deSerializer.IsName(names, ref index))
                {
                    if (index == -1)
                    {
                        return;
                    }
                    memberDeSerializers[index].Call(deSerializer, memberMap, ref value);
                    if (deSerializer.State != DeSerializeState.Success)
                    {
                        return;
                    }
                    if (deSerializer.IsNameEnd(names) == 0)
                    {
                        if (deSerializer.CheckNameEnd((char *)(names + (sizeof(short) + sizeof(char))), (*(short *)names >> 1) - 2) == 0)
                        {
                            return;
                        }
                        break;
                    }
                    ++index;
                    names += *(short *)names + sizeof(short);
                }
                AutoCSer.StateSearcher.CharSearcher searcher = new AutoCSer.StateSearcher.CharSearcher(memberSearcher);
                AutoCSer.Memory.Pointer             name     = default(AutoCSer.Memory.Pointer);
                byte isTagEnd = 0;
                try
                {
                    if (onUnknownName == null)
                    {
                        do
                        {
                            if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                            {
                                return;
                            }
                            if (isTagEnd == 0)
                            {
                                if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                                {
                                    if (deSerializer.IgnoreValue() == 0)
                                    {
                                        return;
                                    }
                                }
                                else if (memberDeSerializers[index].Call(deSerializer, memberMap, ref value) == 0)
                                {
                                    return;
                                }
                                if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                                {
                                    return;
                                }
                            }
                        }while (true);
                    }
                    else
                    {
                        do
                        {
                            if ((name.Data = deSerializer.GetName(ref name.ByteSize, ref isTagEnd)) == null)
                            {
                                return;
                            }
                            if (isTagEnd == 0)
                            {
                                if ((index = searcher.UnsafeSearch(name.Char, name.ByteSize)) == -1)
                                {
                                    name.ByteSize <<= 1;
                                    if (onUnknownName(deSerializer, ref value, ref name))
                                    {
                                        if (deSerializer.State != DeSerializeState.Success)
                                        {
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        if (deSerializer.State == DeSerializeState.Success)
                                        {
                                            deSerializer.State = DeSerializeState.UnknownNameError;
                                        }
                                        return;
                                    }
                                }
                                else if (memberDeSerializers[index].Call(deSerializer, memberMap, ref value) == 0)
                                {
                                    return;
                                }
                                if (deSerializer.CheckNameEnd(name.Char, name.ByteSize) == 0)
                                {
                                    return;
                                }
                            }
                        }while (true);
                    }
                }
                finally { deSerializer.MemberMap = memberMap; }
            }
            else
            {
                deSerializer.State = DeSerializeState.MemberMap;
            }
        }