/// <summary> /// The Type uses EntitySemantics. See <see cref="CEntityTypeData"/> for more info on /// EntitySemantics /// </summary> /// <param name="_xml">The XML containing the data</param> /// <param name="_type"> /// The Type that has already been determined to use Entity Semantics /// </param> /// <param name="_workingObject">Where to put the resulting object</param> private void DeserializeUsingEntitySemantics(XmlElement _xml, Type _type, CWorkingObject _workingObject) { var obj = _workingObject.GetExistingOrCreateNew(_type); var typeData = CEntityTypeData.GetTypeData(_type); for (var i = 0; i < typeData.NonCollectionProperties.Length; i++) { var prop = typeData.NonCollectionProperties[i]; var xml = _xml[prop.Name]; if (xml != null) // There was some XmlElement for the property { // This isn't a Field, and we're using EntitySemantics, so use there's // nothing to query PushCurrentField(null); var propVal = FrameworkDeserialize(xml, prop.PropertyType); prop.SetValue(obj, propVal); PopField(); // pop the null we pushed } } for (var i = 0; i < typeData.CollectionProperties.Length; i++) { var colProp = typeData.CollectionProperties[i]; } }
/// <summary> /// This "different" serializer handles Properties, not Fields, and conforms to the /// conventions found in Microsoft's Entity Framework /// </summary> /// <param name="_object"></param> /// <param name="_useType"></param> /// <param name="_elementForObject"></param> private void SerializeUsingEntitySemantics(object _object, Type _useType, XmlElement _elementForObject) { XmlExtensions.AddAttribute(_elementForObject, m_context.UseEntitySemanticsAttributeName, "1"); // Gets (cached) type data pertinent to serializing an Entity var typeData = CEntityTypeData.GetTypeData(_useType); // First serialize all the "single" properties- No collections for (var i = 0; i < typeData.NonCollectionProperties.Length; i++) { var prop = typeData.NonCollectionProperties[i]; var val = prop.GetValue(_object); FrameworkSerialize(prop.Name, val, _elementForObject, prop.PropertyType); } // Now serialize all the collections which are presumed to be the "Many" in a // Many-To-One relationship. The exact Type of the collection in this object is // irrelevant because the collection should merely implement ICollection for the // deserialization, and the deserialization target class should determine the exact // collection Type, or if its an Interface the PreferredCollectionType on the // AUseEntitySemantics attribute will dictate what to create. for (var i = 0; i < typeData.CollectionProperties.Length; i++) { var col = typeData.CollectionProperties[i]; var collectionElement = XmlExtensions.AddElement(_elementForObject, col.Name); Type elementType = null; // set if the PropertyType is a generic collection if (col.PropertyType.IsGenericType) { elementType = col.PropertyType.GetGenericArguments()[0]; } foreach (var item in col.GetValue(_object) as System.Collections.IEnumerable) { FrameworkSerialize(m_context.ArrayElementName, item, collectionElement, elementType); } } }