/// <summary>
        /// This method writes the specified object.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element.</param>
        /// <param name="pSerializationContext">The serialization context.</param>
        /// <returns>The modified parent element</returns>
        public override XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            try
            {
                // Store the type.
                pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

                // Store all items.
                IDictionary lDictionary = pObject as IDictionary;
                if (lDictionary != null)
                {
                    foreach (var lKey in lDictionary.Keys)
                    {
                        XElement lEntryElement = new XElement(XConstants.ITEM_TAG);
                        IXSerializationContract lKeyContract = pSerializationContext.SelectContract(lEntryElement, lKey);
                        if (lKeyContract != null)
                        {
                            XElement lKeyElement = new XElement(XConstants.KEY_TAG);
                            lKeyContract.Write(lKey, lKeyElement, pSerializationContext);
                            lEntryElement.Add(lKeyElement);
                        }

                        object lValue = lDictionary[lKey];
                        IXSerializationContract lValueContract = pSerializationContext.SelectContract(lEntryElement, lValue);
                        if (lValueContract != null)
                        {
                            // Add the type of the value.
                            Type lValueType = lDictionary.GetType().GetGenericArguments()[1];
                            if (object.ReferenceEquals(lValue, null) == false)
                            {
                                lValueType = lValue.GetType();
                            }
                            lEntryElement.Add(pSerializationContext.ReferenceType(lValueType));
                            XElement lValuelement = new XElement(XConstants.VALUE_TAG);
                            lValueContract.Write(lValue, lValuelement, pSerializationContext);
                            lEntryElement.Add(lValuelement);
                        }


                        pParentElement.Add(lEntryElement);
                    }
                }
            }
            catch
            {
                // Hack to avoid serialization crash due to DynamicTypedObject in tactical data. Need to make a serializer but want to avoid other to stop cretaing scenario :-)
            }

            return(pParentElement);
        }
        /// <summary>
        /// This method writes the specified object.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element.</param>
        /// <param name="pSerializationContext">The serialization context.</param>
        /// <returns>The modified parent element</returns>
        public virtual XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            XElement lValuelement = new XElement(XConstants.VALUE_TAG);

            lValuelement.Value = pObject.ToString();
            pParentElement.Add(lValuelement);

            return(pParentElement);
        }
Exemplo n.º 3
0
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement"></param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            for (int lGenericIndex = 0; lGenericIndex < pObject.GetType().GetGenericArguments().Count(); lGenericIndex++)
            {
                string lItemName = XConstants.TUPLE_ITEM_TAG + (lGenericIndex + 1);
                IXSerializationContract lKeyContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType(lItemName), null);
                if (lKeyContract != null)
                {
                    XElement lKeyElement = new XElement(lItemName);
                    lKeyContract.Write(pObject.GetPropertyValue(lItemName), lKeyElement, pSerializationContext);
                    pParentElement.Add(lKeyElement);
                }
            }

            return(pParentElement);
        }
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element</param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            if (pObject != null)
            {
                Type lNullableType = typeof(Nullable <>).MakeGenericType(pObject.GetType());
                pParentElement.Add(pSerializationContext.ReferenceType(lNullableType));
            }

            XElement lValueElement = new XElement(XConstants.VALUE_TAG);
            IXSerializationContract lSerializationContract = pSerializationContext.SelectContract(pParentElement, pObject);

            if (lSerializationContract != null)
            {
                lSerializationContract.Write(pObject, lValueElement, pSerializationContext);
            }
            pParentElement.Add(lValueElement);

            return(pParentElement);
        }
Exemplo n.º 5
0
        /// <summary>
        /// This method writes the specified object.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element.</param>
        /// <param name="pSerializationContext">The serialization context.</param>lList.GetType().GetGenericArguments()[0]
        /// <returns>The modified parent element</returns>
        public override XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            // Store the type.
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            // Store all items.
            IList lList = pObject as IList;

            foreach (object lItem in lList)
            {
                XElement lItemElement             = new XElement(XConstants.ITEM_TAG);
                IXSerializationContract lContract = pSerializationContext.SelectContract(lItemElement, lItem);
                if (lContract != null)
                {
                    lContract.Write(lItem, lItemElement, pSerializationContext);
                }
                pParentElement.Add(lItemElement);
            }
            return(pParentElement);
        }
        /// <summary>
        /// Writes the specified object.
        /// </summary>
        /// <param name="pObject">The object.</param>
        /// <param name="pParentElement">The parent element.</param>
        /// <param name="pSerializationContext">The serialization context.</param>
        /// <returns></returns>
        public override XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            // Get public propertyinfo and the private one bearing a XSerializationAttribute attribute.
            PropertyInfo[] lPublicPropertyInfos         = pObject.GetType().GetProperties();
            PropertyInfo[] lNonPublicPropertyInfos      = pObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.NonPublic);
            PropertyInfo[] lFilteredPropertyInfos       = lPublicPropertyInfos.Union(lNonPublicPropertyInfos.Where(pElt => pElt.GetCustomAttributes(typeof(IXSerializationAttribute), true).Any())).ToArray();
            PropertyInfo[] lSortedFilteredPropertyInfos = lFilteredPropertyInfos.Select(pX => new { Property = pX, Attribute = (OrderXSerializationAttribute)Attribute.GetCustomAttribute(pX, typeof(OrderXSerializationAttribute), true) }).OrderBy(pX => pX.Attribute != null ? pX.Attribute.Order : Int32.MaxValue).ThenBy(pX => pX.Property.Name).Select(pX => pX.Property).ToArray();
            pParentElement.SetAttributeValue(XConstants.ID_ATTRIBUTE, pSerializationContext.GetObjectReference(pObject));
            foreach (PropertyInfo lPropertyInfo in lSortedFilteredPropertyInfos)
            {
                IXSerializationContract lSerializationContract = pSerializationContext.SelectContract(null, lPropertyInfo);
                if (lSerializationContract != null)
                {
                    lSerializationContract.Write(lPropertyInfo, pParentElement, pSerializationContext);
                }
            }

            return(pParentElement);
        }
Exemplo n.º 7
0
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement"></param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            IXSerializationContract lKeyContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType("Key"), null);

            if (lKeyContract != null)
            {
                XElement lKeyElement = new XElement(XConstants.KEY_TAG);
                lKeyContract.Write(pObject.GetPropertyValue("Key"), lKeyElement, pSerializationContext);
                pParentElement.Add(lKeyElement);
            }

            IXSerializationContract lValueContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType("Value"), null);

            if (lValueContract != null)
            {
                XElement lValueElement = new XElement(XConstants.VALUE_TAG);
                lValueContract.Write(pObject.GetPropertyValue("Value"), lValueElement, pSerializationContext);
                pParentElement.Add(lValueElement);
            }
            return(pParentElement);
        }
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element</param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            if (pObject != null)
            {
                Type lNullableType = typeof(Nullable<>).MakeGenericType(pObject.GetType());
                pParentElement.Add(pSerializationContext.ReferenceType(lNullableType));
            }

            XElement lValueElement = new XElement(XConstants.VALUE_TAG);
            IXSerializationContract lSerializationContract = pSerializationContext.SelectContract(pParentElement, pObject);
            if (lSerializationContract != null)
            {
                lSerializationContract.Write(pObject, lValueElement, pSerializationContext);
            }
            pParentElement.Add(lValueElement);

            return pParentElement;
        }
        /// <summary>
        /// This method writes the specified object.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement">The parent element.</param>
        /// <param name="pSerializationContext">The serialization context.</param>
        /// <returns>The modified parent element</returns>
        public virtual XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            XElement lValuelement = new XElement(XConstants.VALUE_TAG);
            lValuelement.Value = pObject.ToString();
            pParentElement.Add(lValuelement);

            return pParentElement;
        }
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement"></param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            IXSerializationContract lKeyContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType("Key"), null);
            if (lKeyContract != null)
            {
                XElement lKeyElement = new XElement(XConstants.KEY_TAG);
                lKeyContract.Write(pObject.GetPropertyValue("Key"), lKeyElement, pSerializationContext);
                pParentElement.Add(lKeyElement);
            }

            IXSerializationContract lValueContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType("Value"), null);
            if (lValueContract != null)
            {
                XElement lValueElement = new XElement(XConstants.VALUE_TAG);
                lValueContract.Write(pObject.GetPropertyValue("Value"), lValueElement, pSerializationContext);
                pParentElement.Add(lValueElement);
            }
            return pParentElement;
        }
Exemplo n.º 11
0
        /// <summary>
        /// THis method serializes the object in to an XElement.
        /// </summary>
        /// <param name="pObject">The object to serialize.</param>
        /// <param name="pParentElement"></param>
        /// <param name="pSerializationContext">The context of serialization</param>
        /// <returns>
        /// The modified XElement.
        /// </returns>
        public XElement Write(object pObject, XElement pParentElement, IXSerializationContext pSerializationContext)
        {
            pParentElement.Add(pSerializationContext.ReferenceType(pObject.GetType()));

            for (int lGenericIndex = 0; lGenericIndex < pObject.GetType().GetGenericArguments().Count(); lGenericIndex++)
            {
                string lItemName = XConstants.ITEM_TAG + (lGenericIndex + 1);
                IXSerializationContract lKeyContract = pSerializationContext.SelectContract(null, null, pObject.GetPropertyType(lItemName), null);
                if (lKeyContract != null)
                {
                    XElement lKeyElement = new XElement(lItemName);
                    lKeyContract.Write(pObject.GetPropertyValue(lItemName), lKeyElement, pSerializationContext);
                    pParentElement.Add(lKeyElement);
                }
            }

            return pParentElement;
        }