//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange { using System; using System.Collections.Generic; using System.Diagnostics; using DotNetOpenAuth.Messaging; using Validation; /// /// An individual attribute's value(s) as supplied by an OpenID Provider /// in response to a prior request by an OpenID Relying Party as part of /// a fetch request, or by a relying party as part of a store request. /// [Serializable] [DebuggerDisplay("{TypeUri}")] public class AttributeValues { /// /// Initializes a new instance of the class. /// /// The TypeURI that uniquely identifies the attribute. /// The values for the attribute. public AttributeValues(string typeUri, params string[] values) { Requires.NotNullOrEmpty(typeUri, "typeUri"); this.TypeUri = typeUri; this.Values = (IList)values ?? EmptyList.Instance; } /// /// Initializes a new instance of the class. /// /// /// This is internal because web sites should be using the /// method to instantiate. /// internal AttributeValues() { this.Values = new List(1); } /// /// Initializes a new instance of the class. /// /// The TypeURI of the attribute whose values are being provided. internal AttributeValues(string typeUri) { Requires.NotNullOrEmpty(typeUri, "typeUri"); this.TypeUri = typeUri; this.Values = new List(1); } /// /// Gets the URI uniquely identifying the attribute whose value is being supplied. /// public string TypeUri { get; internal set; } /// /// Gets the values supplied by the Provider. /// public IList Values { get; private set; } /// /// Determines whether the specified is equal to the current . /// /// The to compare with the current . /// /// true if the specified is equal to the current ; otherwise, false. /// /// /// The parameter is null. /// public override bool Equals(object obj) { AttributeValues other = obj as AttributeValues; if (other == null) { return false; } if (this.TypeUri != other.TypeUri) { return false; } if (!MessagingUtilities.AreEquivalent(this.Values, other.Values)) { return false; } return true; } /// /// Serves as a hash function for a particular type. /// /// /// A hash code for the current . /// public override int GetHashCode() { int hashCode = 0; unchecked { if (this.TypeUri != null) { hashCode += this.TypeUri.GetHashCode(); } foreach (string value in this.Values) { hashCode += value.GetHashCode(); } } return hashCode; } } }