/// <summary> /// Writes the <saml:SubjectLocality> element. /// </summary> /// <param name="writer">A <see cref="XmlWriter"/> to serialize the <see cref="Saml2SubjectLocality"/>.</param> /// <param name="data">The <see cref="Saml2SubjectLocality"/> to serialize.</param> protected virtual void WriteSubjectLocality(XmlWriter writer, Saml2SubjectLocality data) { if (null == writer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (null == data) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("data"); } // <SubjectLocality> writer.WriteStartElement(Saml2Constants.Elements.SubjectLocality, Saml2Constants.Namespace); // @Address - optional if (null != data.Address) { writer.WriteAttributeString(Saml2Constants.Attributes.Address, data.Address); } // @DNSName - optional if (null != data.DnsName) { writer.WriteAttributeString(Saml2Constants.Attributes.DNSName, data.DnsName); } // </SubjectLocality> writer.WriteEndElement(); }
/// <summary> /// Reads the <saml:SubjectLocality> element. /// </summary> /// <param name="reader">A <see cref="XmlReader"/> positioned at a <see cref="Saml2SubjectLocality"/> element.</param> /// <returns>An instance of <see cref="Saml2SubjectLocality"/> .</returns> protected virtual Saml2SubjectLocality ReadSubjectLocality(XmlReader reader) { if (null == reader) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); } // throw if wrong element if (!reader.IsStartElement(Saml2Constants.Elements.SubjectLocality, Saml2Constants.Namespace)) { reader.ReadStartElement(Saml2Constants.Elements.SubjectLocality, Saml2Constants.Namespace); } try { Saml2SubjectLocality subjectLocality = new Saml2SubjectLocality(); bool isEmpty = reader.IsEmptyElement; // @attributes // @xsi:type XmlUtil.ValidateXsiType(reader, Saml2Constants.Types.SubjectLocalityType, Saml2Constants.Namespace); // @Address - optional subjectLocality.Address = reader.GetAttribute(Saml2Constants.Attributes.Address); // @DNSName - optional subjectLocality.DnsName = reader.GetAttribute(Saml2Constants.Attributes.DNSName); // Empty content reader.Read(); if (!isEmpty) { reader.ReadEndElement(); } return subjectLocality; } catch (Exception e) { if (System.Runtime.Fx.IsFatal(e)) throw; Exception wrapped = TryWrapReadException(reader, e); if (null == wrapped) { throw; } else { throw wrapped; } } }