Esempio n. 1
0
        private static bool CreateFromXml(XmlElement _node, CWorkingObject _object, CDeserializer _framework)
        {
            var x = _object.GetExistingOrCreateNew <CStdImplicitSurrogate>();

            x.Name = XmlExtensions.GetAttributeValue(_node, "NAME");
            x.Age  = int.Parse(XmlExtensions.GetAttributeValue(_node, "AGE"));

            STATUS = ETestStatus.IMPLICIT_DESERIALIZER;
            return(true);
        }
        /// <summary>
        /// Enumerate through the child nodes of the collection and deserialize each one. Use the
        /// method provided to add each element to the collection.
        /// </summary>
        /// <param name="_object">The working object to receive the data about the Stack</param>
        /// <param name="_parentNode">The node containing the elements of the Stack</param>
        /// <param name="_deserializer">The Deserializer controlling this deserializtion</param>
        /// <returns>TRUE always</returns>
        protected bool BasicDeserialize(CWorkingObject _object, XmlElement _parentNode, CDeserializer _deserializer)
        {
            if (!ATreatAsInterface.TreatAsInterface(_deserializer))
            {
                return(false);
            }

            var theCollection = _object.GetExistingOrCreateNew <TCollectionType>();

            foreach (XmlElement element in GetXmlChildren(_parentNode))
            {
                var theElement = (TElementType)_deserializer.FrameworkDeserialize(element, typeof(TElementType));
                AddElement(theCollection, theElement);
            }

            return(true);
        }
        /// <summary>
        /// Deserialize a series of "ChildNode"s from an XmlElement as elements for a generic Dictionary.
        /// </summary>
        /// <param name="_workingObject">The "working" object to receive the dictionary elements</param>
        /// <param name="_parentElement">The "parent" of the XmlElements containing the individual Dictionary elements</param>
        /// <param name="_deserializer">The deserialization framework handing the deserialization</param>
        /// <returns>TRUE unless the collection is not supposed to be treated like an "interface"</returns>
        public bool Deserialize(CWorkingObject _workingObject, XmlElement _parentElement, CDeserializer _deserializer)
        {
            if (!ATreatAsInterface.TreatAsInterface(_deserializer))
            {
                return(false);
            }

            var oType = _workingObject.WorkingType;

            if (oType == null)
            {
                oType = _deserializer.GetExpectedType(_parentElement);
            }
            if (oType == null)
            {
                throw new XDeserializationError(
                          "When deserializing a generic collection, the actual Type of the collection could not be found.");
            }

            var expectedTypes = oType.GetGenericArguments();

            if (expectedTypes.Length != NumberOfExpectedTypes)
            {
                throw new XDeserializationError("The Type '" + oType.FullName + "' has " + expectedTypes.Length +
                                                " generic arguments when it is required to have exactly " + NumberOfExpectedTypes + ".");
            }

            var collection  = _workingObject.GetExistingOrCreateNew(oType);
            var elementName = _deserializer.GetNameForCollectionElement();

            foreach (XmlElement xmlElement in GetXmlChildren(_parentElement))
            {
                if (xmlElement.Name == elementName)
                {
                    AddElementFromXml(collection, xmlElement, expectedTypes, _deserializer);
                }
            }

            return(true);
        }