diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-12 08:40:50 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-01-12 08:42:14 -0800 |
commit | af21cdaf77ca72f54e04f22268b740ce262582fa (patch) | |
tree | 9b158e3bff1f56264bccb9e45c8b807816beece6 /src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs | |
parent | a73f2a4830aaa2afcb3f13da2206d9b011dad7fb (diff) | |
download | DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.zip DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.tar.gz DotNetOpenAuth-af21cdaf77ca72f54e04f22268b740ce262582fa.tar.bz2 |
Renamed assembly DotNetOpenAuth.Messaging(.UI) to DotNetOpenAuth.Core(.UI)
Diffstat (limited to 'src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs')
-rw-r--r-- | src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs b/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs new file mode 100644 index 0000000..c7d963b --- /dev/null +++ b/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs @@ -0,0 +1,70 @@ +//----------------------------------------------------------------------- +// <copyright file="HostNameOrRegexCollection.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Configuration { + using System.Collections.Generic; + using System.Configuration; + using System.Diagnostics.Contracts; + using System.Text.RegularExpressions; + + /// <summary> + /// Represents a collection of child elements that describe host names either as literal host names or regex patterns. + /// </summary> + [ContractVerification(true)] + internal class HostNameOrRegexCollection : ConfigurationElementCollection { + /// <summary> + /// Initializes a new instance of the <see cref="HostNameOrRegexCollection"/> class. + /// </summary> + public HostNameOrRegexCollection() { + } + + /// <summary> + /// Gets all the members of the collection assuming they are all literal host names. + /// </summary> + internal IEnumerable<string> KeysAsStrings { + get { + foreach (HostNameElement element in this) { + yield return element.Name; + } + } + } + + /// <summary> + /// Gets all the members of the collection assuming they are all host names regex patterns. + /// </summary> + internal IEnumerable<Regex> KeysAsRegexs { + get { + foreach (HostNameElement element in this) { + if (element.Name != null) { + yield return new Regex(element.Name); + } + } + } + } + + /// <summary> + /// Creates a new child host name element. + /// </summary> + /// <returns> + /// A new <see cref="T:System.Configuration.ConfigurationElement"/>. + /// </returns> + protected override ConfigurationElement CreateNewElement() { + return new HostNameElement(); + } + + /// <summary> + /// Gets the element key for a specified configuration element. + /// </summary> + /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param> + /// <returns> + /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>. + /// </returns> + protected override object GetElementKey(ConfigurationElement element) { + Contract.Assume(element != null); // this should be Contract.Requires in base class. + return ((HostNameElement)element).Name ?? string.Empty; + } + } +} |