/// <summary>
        /// Load from xml.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Retention policy tag object.</returns>
        internal static RetentionPolicyTag LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.RetentionPolicyTag);

            RetentionPolicyTag retentionPolicyTag = new RetentionPolicyTag();

            retentionPolicyTag.DisplayName     = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.DisplayName);
            retentionPolicyTag.RetentionId     = new Guid(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.RetentionId));
            retentionPolicyTag.RetentionPeriod = reader.ReadElementValue <int>(XmlNamespace.Types, XmlElementNames.RetentionPeriod);
            retentionPolicyTag.Type            = reader.ReadElementValue <ElcFolderType>(XmlNamespace.Types, XmlElementNames.Type);
            retentionPolicyTag.RetentionAction = reader.ReadElementValue <RetentionActionType>(XmlNamespace.Types, XmlElementNames.RetentionAction);

            // Description is not a required property.
            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Description))
            {
                retentionPolicyTag.Description = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Description);
            }

            retentionPolicyTag.IsVisible = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsVisible);
            retentionPolicyTag.OptedInto = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.OptedInto);
            retentionPolicyTag.IsArchive = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsArchive);

            return(retentionPolicyTag);
        }
        /// <summary>
        /// Load from json.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns>Retention policy tag object.</returns>
        internal static RetentionPolicyTag LoadFromJson(JsonObject jsonObject)
        {
            RetentionPolicyTag retentionPolicyTag = new RetentionPolicyTag();

            if (jsonObject.ContainsKey(XmlElementNames.DisplayName))
            {
                retentionPolicyTag.DisplayName = jsonObject.ReadAsString(XmlElementNames.DisplayName);
            }

            if (jsonObject.ContainsKey(XmlElementNames.RetentionId))
            {
                retentionPolicyTag.RetentionId = new Guid(jsonObject.ReadAsString(XmlElementNames.RetentionId));
            }

            if (jsonObject.ContainsKey(XmlElementNames.RetentionPeriod))
            {
                retentionPolicyTag.RetentionPeriod = jsonObject.ReadAsInt(XmlElementNames.RetentionPeriod);
            }

            if (jsonObject.ContainsKey(XmlElementNames.Type))
            {
                retentionPolicyTag.Type = jsonObject.ReadEnumValue <ElcFolderType>(XmlElementNames.Type);
            }

            if (jsonObject.ContainsKey(XmlElementNames.RetentionAction))
            {
                retentionPolicyTag.RetentionAction = jsonObject.ReadEnumValue <RetentionActionType>(XmlElementNames.RetentionAction);
            }

            if (jsonObject.ContainsKey(XmlElementNames.Description))
            {
                retentionPolicyTag.Description = jsonObject.ReadAsString(XmlElementNames.Description);
            }

            if (jsonObject.ContainsKey(XmlElementNames.IsVisible))
            {
                retentionPolicyTag.IsVisible = jsonObject.ReadAsBool(XmlElementNames.IsVisible);
            }

            if (jsonObject.ContainsKey(XmlElementNames.OptedInto))
            {
                retentionPolicyTag.OptedInto = jsonObject.ReadAsBool(XmlElementNames.OptedInto);
            }

            if (jsonObject.ContainsKey(XmlElementNames.IsArchive))
            {
                retentionPolicyTag.IsArchive = jsonObject.ReadAsBool(XmlElementNames.IsArchive);
            }

            return(retentionPolicyTag);
        }
        /// <summary>
        /// Reads response elements from Json.
        /// </summary>
        /// <param name="responseObject">The response object.</param>
        /// <param name="service">The service.</param>
        internal override void ReadElementsFromJson(JsonObject responseObject, ExchangeService service)
        {
            this.retentionPolicyTags.Clear();

            base.ReadElementsFromJson(responseObject, service);

            if (responseObject.ContainsKey(XmlElementNames.RetentionPolicyTags))
            {
                foreach (object retentionPolicyTagObject in responseObject.ReadAsArray(XmlElementNames.RetentionPolicyTags))
                {
                    JsonObject jsonRetentionPolicyTag = retentionPolicyTagObject as JsonObject;
                    this.retentionPolicyTags.Add(RetentionPolicyTag.LoadFromJson(jsonRetentionPolicyTag));
                }
            }
        }
        /// <summary>
        /// Reads response elements from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
        {
            this.retentionPolicyTags.Clear();

            base.ReadElementsFromXml(reader);

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.RetentionPolicyTags);
            if (!reader.IsEmptyElement)
            {
                do
                {
                    reader.Read();
                    if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.RetentionPolicyTag))
                    {
                        this.retentionPolicyTags.Add(RetentionPolicyTag.LoadFromXml(reader));
                    }
                }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.RetentionPolicyTags));
                reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.RetentionPolicyTags);
            }
        }
        /// <summary>
        /// Load from xml.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Retention policy tag object.</returns>
        internal static RetentionPolicyTag LoadFromXml(EwsServiceXmlReader reader)
        {
            reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, XmlElementNames.RetentionPolicyTag);

            RetentionPolicyTag retentionPolicyTag = new RetentionPolicyTag();
            retentionPolicyTag.DisplayName = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.DisplayName);
            retentionPolicyTag.RetentionId = new Guid(reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.RetentionId));
            retentionPolicyTag.RetentionPeriod = reader.ReadElementValue<int>(XmlNamespace.Types, XmlElementNames.RetentionPeriod);
            retentionPolicyTag.Type = reader.ReadElementValue<ElcFolderType>(XmlNamespace.Types, XmlElementNames.Type);
            retentionPolicyTag.RetentionAction = reader.ReadElementValue<RetentionActionType>(XmlNamespace.Types, XmlElementNames.RetentionAction);

            // Description is not a required property.
            reader.Read();
            if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.Description))
            {
                retentionPolicyTag.Description = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Description);
            }

            retentionPolicyTag.IsVisible = reader.ReadElementValue<bool>(XmlNamespace.Types, XmlElementNames.IsVisible);
            retentionPolicyTag.OptedInto = reader.ReadElementValue<bool>(XmlNamespace.Types, XmlElementNames.OptedInto);
            retentionPolicyTag.IsArchive = reader.ReadElementValue<bool>(XmlNamespace.Types, XmlElementNames.IsArchive);

            return retentionPolicyTag;
        }