Exemple #1
0
 /// <summary>
 /// The framework will deserialize the object. No more surrogates or other "exceptional"
 /// behaviour.
 /// </summary>
 /// <param name="_xml"></param>
 /// <param name="_type"></param>
 /// <param name="_workingObject"></param>
 private void HandleDeserialization(XmlElement _xml, Type _type, CWorkingObject _workingObject)
 {
     // Strings are really easy- just return the "InnerText"
     if (_type == TYPEOF_STRING)
     {
         _workingObject.Set(Environment.ExpandEnvironmentVariables(_xml.InnerText));
     }
     // Primitives are also pretty easy, only because of the "Convert" class
     else if (_type.IsPrimitive)
     {
         _workingObject.Set(Convert.ChangeType(_xml.InnerText, _type));
     }
     // Check for an Array
     else if (_type.IsArray || XmlExtensions.HasAttribute(_xml, m_context.ArrayAttributeName))
     {
         DeserializeArray(_xml, _type, _workingObject);
     }
     else if (_type.IsEnum)
     {
         _workingObject.Set(Enum.Parse(_type, _xml.InnerText, false));
     }
     else // Handle ref-type fields and base classes.
     {
         DeserializeReferenceType(_xml, _type, _workingObject);
     }
 }
Exemple #2
0
        /// <summary>
        /// Check the easiest forms of deserialization- Null and RefTo an object already
        /// deserialized.
        /// </summary>
        /// <param name="_xml">The XML that's being deserialized</param>
        /// <param name="_workObj">
        /// The Object that was deserialized (when the return value is TRUE)
        /// </param>
        /// <returns>
        /// TRUE means that the _workObj parameter contains valid data and nothing further
        /// should be done, FALSE means that no deserialization was performed.
        /// </returns>
        private bool CheckNullAndReference(XmlElement _xml, CWorkingObject _workObj)
        {
            // Check the XML to see if this is a NULL object reference. If it is, then return
            // TRUE.
            if (XmlExtensions.HasAttribute(_xml, m_context.NullAttributeName))
            {
                return(true);
            }

            // Check the XML to see if its referring to some other object.
            var referTo = XmlExtensions.GetAttributeValue(_xml, m_context.ReferToAttributeName);

            if (referTo != null) // There was a reference to another object, so handle it and return that other object.
            {
                // Check the table for the RefID to get the object. The reference must be in the
                // table already because forward-looking references are not supported.
                if (!m_references.TryGetValue(referTo, out var obj))
                {
                    throw new XUnknownReference("All object-references must be to backward-defined objects. The RefID " + referTo + " has not been defined yet.");
                }

                _workObj.Set(obj);
                return(true);
            }

            // Check to see if this element is associating the XML with a reference ID
            var refId = XmlExtensions.GetAttributeValue(_xml, m_context.ReferenceIdAttributeName);

            if (refId != null)
            {
                _workObj.SetRefInfo(this, refId);
            }

            return(false);
        }