//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------- namespace System.IdentityModel.Tokens { using System; using System.Xml; /// /// Represents the identifier used for SAML assertions. /// ///
/// This identifier should be unique per [Saml2Core, 1.3.4] /// and must fit the NCName xml schema definition, which is to say that /// it must begin with a letter or underscore. ///
public class Saml2Id { private string value; /// /// Creates a new ID value based on a GUID. /// public Saml2Id() : this(System.IdentityModel.UniqueId.CreateRandomId()) { } /// /// Creates a new ID whose value is the given string. /// /// The Saml2 Id. /// If the value is not a valid NCName. public Saml2Id(string value) { if (string.IsNullOrEmpty(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } try { this.value = XmlConvert.VerifyNCName(value); } catch (XmlException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new ArgumentException(SR.GetString(SR.ID4128), "value", e)); } } /// /// Gets the identifier string. /// public string Value { get { return this.value; } } /// /// Compares two for equality. /// /// Object to campare to. /// True if this equals object. False otherwise. public override bool Equals(object obj) { if (Object.ReferenceEquals(this, obj)) { return true; } Saml2Id other = obj as Saml2Id; #pragma warning suppress 56506 // PreSharp thinks other can be null-dereffed here return (null != other) && StringComparer.Ordinal.Equals(this.value, other.Value); } /// /// Gets the hash code for the as an integer. /// /// The hash code for this object. public override int GetHashCode() { return this.value.GetHashCode(); } /// /// Gets the in text format. /// /// The string representation of this object. public override string ToString() { return this.value; } } }