Beispiel #1
0
#pragma warning disable CS1574 // XML comment has cref attribute 'content' that could not be resolved
        /// <summary>
        /// Serializes and stores an item into <see cref="content"/> collection. , before serialization it calls <see cref="IDataPackageItem.OnBeforeSave"/>
        /// </summary>
        /// <param name="wrapper">The wrapper to use for <see cref="dataItemContainer.id"/> and <see cref="dataItemContainer.instanceXml"/> creation</param>
        /// <param name="xmlSer">The XML serializer to use instead of its own.</param>
        /// <remarks>Makes the container using <see cref="GetInstanceToPack(TWrapper)"/> and <see cref="GetDataPackageID(TWrapper)"/>. Calls <see cref="IDataPackageItem.OnBeforeSave"/> between these two.</remarks>
        /// <returns></returns>
        protected virtual dataItemContainer AddDataItem(TWrapper wrapper, XmlSerializer xmlSer = null)
#pragma warning restore CS1574 // XML comment has cref attribute 'content' that could not be resolved
        {
            dataItemContainer iContainer = new dataItemContainer();
            T item = GetInstanceToPack(wrapper);

            if (item is IDataPackageItem)
            {
                IDataPackageItem item_IDataPackageItem = (IDataPackageItem)item;
                item_IDataPackageItem.OnBeforeSave();
            }

            iContainer.id = GetDataPackageID(wrapper);

            TextWriter writer = new StringWriter();

            if (xmlSer == null)
            {
                xmlSer = xSer;
            }

            xmlSer.Serialize(writer, item);
            writer.Close();

            iContainer.instanceXml = writer.ToString();

            content.Add(iContainer);
            return(iContainer);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the item.
        /// </summary>
        /// <param name="iContainer">The i container.</param>
        /// <returns></returns>
        protected virtual instanceItemContainer <T> GetItem(dataItemContainer iContainer)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(T));
            TextReader    reader       = new StringReader(iContainer.instanceXml);
            object        obj          = deserializer.Deserialize(reader);
            T             output       = (T)obj;

            reader.Close();

            return(new instanceItemContainer <T>(iContainer.id, output));
        }