Пример #1
0
        internal override object ReadObjectData(IList <INodeData> list, DeserializationContext context, int currentIndex)
        {
            // prepare the instance to deserialize into
            object instance = Activator.CreateInstance(CollectionType.MakeGenericType(ElementsType));

            if (currentIndex != -1)
            {
                // note : we do this to count for the case where instance A has itself as one of its properties
                // so we have to preregister the parent to catch it back when we encounter it back as a property
                context.Register(currentIndex, instance);
            }

            list = list[0].SubNodes[1].SubNodes.Where(n => !NodeUtils.IgnoreOnDeserialization(n.Type)).ToList();

            IList cast = (IList)instance;

            foreach (INodeData el in list)
            {
                object desElement = SerializerDependencies.SerializerCollection
                                    .GetOrAdd(ElementsType)
                                    .DeserializeInternal(el.Data, context);
                cast.Add(desElement);
            }

            return(cast);
        }
Пример #2
0
        internal override object ReadObjectData(IList <INodeData> list, DeserializationContext context, int currentIndex)
        {
            // prepare the instance to deserialize into
            object instance = Activator.CreateInstance(Type);

            if (currentIndex != -1)
            {
                // note : we do this to count for the case where instance A has itself as one of its properties
                // so we have to preregister the parent to catch it back when we encounter it back as a property
                context.Register(currentIndex, instance);
            }

            //list = list[0].SubNodes[1].SubNodes.Where(n => !).ToList();

            list = list[0].SubNodes[1].SubNodes;

            int propIndex = 0;

            int nodeIndex = -1;

            for (int i = 0; i < PropertiesCount; i++)
            {
                while (nodeIndex < list.Count)
                {
                    nodeIndex++;
                    if (!NodeUtils.IgnoreOnDeserialization(list[nodeIndex].Type))
                    {
                        break;
                    }
                }

                INodeData node = list[nodeIndex];

                /*
                 * if (node.Type == Parser.NodeType.COMMENT)
                 *  continue;
                 * if (node.Type == Parser.NodeType.SYMBOL)
                 *  continue;
                 */
                object val = Serializers[propIndex].DeserializeInternal(node.Data, context);

                PropertieSetter[i].Invoke(instance, val);

                propIndex++;
            }

            return(instance);
        }