public bool Deserialize(CWorkingObject _workingObject, XmlElement _parentNode, CDeserializer _deserializer) { Count++; return(false); }
/// <summary> /// Deserialization helper to deserialize XML nodes into a "special" collection. /// </summary> /// <remarks> /// A "special" collection is one of the "hidden" collections that implement Synchronized or ReadOnly /// behavior for the System.Collections collections. /// </remarks> /// <param name="_object">The working object to receive the deserialized values</param> /// <param name="_node">The XmlNode containing the data for the collection</param> /// <param name="_deserializer">The deserialization framework performing the overall deserialization</param> /// <returns>TRUE always</returns> protected bool SpecialDeserialize(CWorkingObject _object, XmlElement _node, CDeserializer _deserializer) { if (!ATreatAsInterface.TreatAsInterface(_deserializer)) { return(false); } // First, get an object to deserialize into var tmp = new CWorkingObject(); if (_object.WorkingObject != null) { tmp.Set(_object.WorkingObject); } // Deserialize into the temporary WorkingObject BasicDeserialize(tmp, _node, _deserializer); // At this point, IF there was an object set in _object prior to this routine, its contents // should have been set by the standard collection deserialization and we should be done. if (_object.IsSet) { return(true); } // Get the collection object populated so far with information from the Xml var tmpCollection = tmp.GetWorkingObject <TCollectionType>(); // Using that object, create a new, syncronized version of that ArrayList. var specialCollection = MakeSpecialCollection(tmpCollection); // Set this sync'ed version to the _object, and we're done _object.Set(specialCollection); return(true); }
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); }
private static void CreateFromXml(XmlElement _node, CWorkingObject _object, CDeserializer _framework) { var x = new CVoidImplicitSurrogate(); _object.Set(x); x.Name = XmlExtensions.GetAttributeValue(_node, "NAME"); x.Age = int.Parse(XmlExtensions.GetAttributeValue(_node, "AGE")); STATUS = ETestStatus.IMPLICIT_DESERIALIZER_VOID; }
public void TestUtcStringProperty() { // The default global property is FALSE for UTC strings. Assert.IsFalse(CSerializationContext.Global.UseFullUtcDateTimeStrings, "The default global value of UtcStrings is FALSE."); var c = new CSerializationContext(); Assert.IsFalse(c.UseFullUtcDateTimeStrings, "Inheriting from the default global context should not use UtcStrings"); CSerializationContext.Global.UseFullUtcDateTimeStrings = true; Assert.IsTrue(CSerializationContext.Global.UseFullUtcDateTimeStrings, "The After setting the global context to Use Utc Strings, the prop should be TRUE."); Assert.IsTrue(c.UseFullUtcDateTimeStrings, "Because the global context changed, the dependant context should also change."); c.UseFullUtcDateTimeStrings = false; Assert.IsFalse(c.UseFullUtcDateTimeStrings, "Setting the dependant context to FALSE should be reflected in the prop-Getter"); Assert.IsTrue(CSerializationContext.Global.UseFullUtcDateTimeStrings, "Changing the Dependant context should not modify the Global context."); c.UseFullUtcDateTimeStrings = true; // This explicitly means that the dependant context should use strings. Assert.IsTrue(c.UseFullUtcDateTimeStrings, "Setting the dependant context to TRUE should be reflected in the prop-Getter"); CSerializationContext.Global.UseFullUtcDateTimeStrings = false; Assert.IsFalse(CSerializationContext.Global.UseFullUtcDateTimeStrings, "Make sure that the GLOBAL property is set to FALSE"); Assert.IsTrue(c.UseFullUtcDateTimeStrings, "Make sure that the dependant context's override survives the modification of the Global value"); var d = new DateTime(2000, 7, 5, 1, 2, 3); var expected = d.ToString(CUtcDateTimeSurrogate.UTC_COMPLETE_DATE_TIME_FORMAT); var sur = new CUtcDateTimeSurrogate(); var doc = new XmlDocument(); doc.LoadXml("<root />"); var retval = sur.Serialize(d, d.GetType(), doc.DocumentElement, null); Assert.AreEqual(expected, doc.DocumentElement.InnerText, "The UTC serialization didn't yield the correct string."); Assert.IsTrue(retval, "The surrogate should always indicate that it completely processed the object"); var w = new CWorkingObject(); retval = sur.Deserialize(w, doc.DocumentElement, null); Assert.AreEqual(d, w.WorkingObject, "The deserialized DateTime is incorrect."); Assert.IsTrue(retval, "The surrogate should always indicate that it completely processed the object"); }
public bool Deserialize(CWorkingObject _workingObject, XmlElement _parentNode, CDeserializer _deserializer) { var sLen = XmlExtensions.GetAttributeValue(_parentNode, "MYLEN"); var len = int.Parse(sLen); _workingObject.Set(Array.CreateInstance(typeof(int), len + 1)); // This actually is a no-no, but i'm testing to make sure // that this is really the array that's being returned. return(false); }
public bool Deserialize(CWorkingObject _workingObject, XmlElement _parentNode, CDeserializer _framework) { _framework.IgnoreField("FriendPerson"); var sIdx = XmlExtensions.GetElementValue(_parentNode, "FriendPerson"); var idx = int.Parse(sIdx); if (m_indicies == null) { m_indicies = new List <int>(); } m_indicies.Add(idx); return(false); }
public bool Deserialize(CWorkingObject _object, XmlElement _node, CDeserializer _framework) { if (_object.WorkingObject == null) { _object.Set(new CStdBaseObject()); } var x = _object.WorkingObject as CStdBaseObject; x.Name = XmlExtensions.GetAttributeValue(_node, "NAME"); x.Age = int.Parse(XmlExtensions.GetAttributeValue(_node, "AGE")); CStdBaseObject.STATUS = ETestStatus.EXTERNAL_DESERIALIZER; return(true); }
public void TestNoSurrogate() { var x = new CNothingImplicitHere(); var s = new CSurrogate(typeof(CNothingImplicitHere)); var isComplete = s.Serialize(x, null, null); Assert.AreEqual(false, isComplete, "Expected the surrogate NOT to complete serialization"); var newObj = new CWorkingObject(); isComplete = s.Deserialize(newObj, null, null); Assert.AreEqual(false, isComplete, "Expected the surrogate NOT to compelte deserialization"); Assert.IsNull(newObj.WorkingObject, "Did not expect any object to be returned from Deserialization"); }
private static bool CreateFromXml(CWorkingObject _object, XmlElement _node, CDeserializer _framework) { if (_object.WorkingObject == null) { _object.Set(new CIncompleteImplicitSurrogate()); } if ("Yes" != XmlExtensions.GetAttributeValue(_node, "Incomplete")) { throw new InvalidOperationException( "Expected an attribute named 'Incomplete' and that attrribute to have the value 'Yes'."); } STATUS = ETestStatus.IMPLICIT_DESERIALIZER_INCOMPLETE; return(false); }
/// <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); }
public void TestDeserializeIncompleteWithError() { try { var s = new CSurrogate(typeof(CIncompleteImplicitSurrogate)); var doc = new XmlDocument(); doc.LoadXml("<_ NAME=\"Mike\" AGE='69' />"); CStdBaseObject.STATUS = ETestStatus.NONE; var o = new CWorkingObject(); var isComplete = s.Deserialize(o, doc.DocumentElement, null); // Generate the error here. } catch (TargetInvocationException e) { throw e.GetBaseException(); } }
public void TestDeserializeIncomplete() { CIncompleteImplicitSurrogate x = null; var s = new CSurrogate(typeof(CIncompleteImplicitSurrogate)); var doc = new XmlDocument(); doc.LoadXml("<_ NAME=\"Mike\" AGE='69' Incomplete='Yes' />"); CStdBaseObject.STATUS = ETestStatus.NONE; var o = new CWorkingObject(); var isComplete = s.Deserialize(o, doc.DocumentElement, null); x = (CIncompleteImplicitSurrogate)o.WorkingObject; Assert.AreEqual(false, isComplete, "Expected the deserializer to be incomplete."); Assert.AreEqual(ETestStatus.IMPLICIT_DESERIALIZER_INCOMPLETE, CStdImplicitSurrogate.STATUS, "The status was not correctly set."); }
/// <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); }
/// <summary> /// Enumerate through the child nodes of an Stack and deserialize each one. Use the /// <see cref="Stack.Push"/> method to add each element to the Stack. /// </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> public bool Deserialize(CWorkingObject _object, XmlElement _parentNode, CDeserializer _deserializer) => BasicDeserialize(_object, _parentNode, _deserializer);
public bool Deserialize(CWorkingObject _object, XmlElement _parentNode, CDeserializer _framework) => throw new Exception("The method or operation is not implemented.");
public bool Deserialize(CWorkingObject _object, XmlElement _node, CDeserializer _framework) { CStdBaseObject.STATUS = ETestStatus.EXTERNAL_DESERIALIZER_INCOMPLETE; return(false); }
private static bool DeserializerWithoutXml(CWorkingObject _object) => true;
public bool Deserialize(CWorkingObject _workingObject, XmlElement _parentElement, CDeserializer _deserializer) { DESER_STATUS |= 2; return(false); }