コード例 #1
0
        public void WriteXml(XmlWriter writer)
        {
            XmlDocument xmlTemplate = XmlLoader.GetXmlTemplate(base.GetType(), 0);
            XmlNode     xml         = xmlTemplate.SelectSingleNode("MailMessage");

            XmlLoader.SetNode(ref xml, "Body", base.Body);
            XmlLoader.SetNode(ref xml, "Subject", base.Subject);
            XmlLoader.SetNode <MailAddressXml>(ref xml, "Bcc", "MailAddress", MailAddressXml.CopyCollection(base.Bcc));
            XmlLoader.SetNode <MailAddressXml>(ref xml, "Cc", "MailAddress", MailAddressXml.CopyCollection(base.CC));
            XmlLoader.SetNode <MailAddressXml>(ref xml, "To", "MailAddress", MailAddressXml.CopyCollection(base.To));
            XmlLoader.SetNode(ref xml, "From/MailAddress", (IXmlSerializable) new MailAddressXml(base.From));
            XmlLoader.SetNode(ref xml, "Sender/MailAddress", (IXmlSerializable) new MailAddressXml(base.Sender));
            XmlLoader.SetNode(ref xml, "ReplyTo/MailAddress", (IXmlSerializable) new MailAddressXml(base.ReplyTo));
            XmlLoader.SetNode(ref xml, "Priority", base.Priority);
            XmlLoader.SetNode(ref xml, "IsBodyHtml", base.IsBodyHtml);
            XmlLoader.SetNode(ref xml, "Headers", base.Headers);
            XmlLoader.SetNode(ref xml, "DeliveryNotificationOptions", base.DeliveryNotificationOptions);
            if (base.BodyEncoding != null)
            {
                XmlLoader.SetNode(ref xml, "BodyEncoding", base.BodyEncoding.CodePage);
            }
            if (base.SubjectEncoding != null)
            {
                XmlLoader.SetNode(ref xml, "SubjectEncoding", base.SubjectEncoding.CodePage);
            }
            SetNode(ref xml, "Attachments", base.Attachments);
            XmlLoader.WriteInnerXml(xmlTemplate, writer);
        }
コード例 #2
0
        public void ReadXml(XmlReader reader)
        {
            string str;
            object obj;
            int    num;
            bool   flag;
            NameValueCollection          values;
            IList <Attachment>           attachment;
            ICollection <MailAddressXml> address;
            XmlDocument doc = new XmlDocument();

            doc.Load(reader);
            XmlNode xml = doc.SelectSingleNode("MailMessage");

            if (XmlLoader.GetStringValue(xml, "Body", out str))
            {
                base.Body = str;
            }
            if (XmlLoader.GetStringValue(xml, "Subject", out str))
            {
                base.Subject = str;
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "Bcc/*", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.Bcc);
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "Cc/MailAddress", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.CC);
            }
            if (XmlLoader.GetCollectionValue <MailAddressXml>(xml, "To/MailAddress", new MailAddressXml(), out address))
            {
                MailAddressXml.CopyCollection(address, base.To);
            }
            if (XmlLoader.GetSerializedObject(xml, "From/MailAddress", new MailAddressXml(), out obj))
            {
                base.From = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetSerializedObject(xml, "ReplyTo/MailAddress", new MailAddressXml(), out obj))
            {
                base.ReplyTo = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetSerializedObject(xml, "Sender/MailAddress", new MailAddressXml(), out obj))
            {
                base.Sender = ((MailAddressXml)obj).MailAddress;
            }
            if (XmlLoader.GetEnumValue(xml, "Priority", typeof(MailPriority), out obj))
            {
                base.Priority = (MailPriority)obj;
            }
            if (XmlLoader.GetBoolValue(xml, "IsBodyHtml", out flag))
            {
                base.IsBodyHtml = flag;
            }
            if (XmlLoader.GetCollectionValue(xml, "Headers", out values))
            {
                TypeHelper.CopyCollection(values, base.Headers);
            }
            if (XmlLoader.GetEnumValue(xml, "DeliveryNotificationOptions", typeof(DeliveryNotificationOptions), out obj))
            {
                base.DeliveryNotificationOptions = (DeliveryNotificationOptions)obj;
            }
            if (XmlLoader.GetIntValue(xml, "BodyEncoding", out num))
            {
                base.BodyEncoding = Encoding.GetEncoding(num);
            }
            if (XmlLoader.GetIntValue(xml, "SubjectEncoding", out num))
            {
                base.SubjectEncoding = Encoding.GetEncoding(num);
            }
            if (GetCollectionValue(xml, "Attachments/Attachment", out attachment))
            {
                TypeHelper.CopyCollection <Attachment>(attachment, base.Attachments);
            }
        }