//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Configuration {
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.Contracts;
using System.Text.RegularExpressions;
///
/// Represents a collection of child elements that describe host names either as literal host names or regex patterns.
///
[ContractVerification(true)]
internal class HostNameOrRegexCollection : ConfigurationElementCollection {
///
/// Initializes a new instance of the class.
///
public HostNameOrRegexCollection() {
}
///
/// Gets all the members of the collection assuming they are all literal host names.
///
internal IEnumerable KeysAsStrings {
get {
foreach (HostNameElement element in this) {
yield return element.Name;
}
}
}
///
/// Gets all the members of the collection assuming they are all host names regex patterns.
///
internal IEnumerable KeysAsRegexs {
get {
foreach (HostNameElement element in this) {
if (element.Name != null) {
yield return new Regex(element.Name);
}
}
}
}
///
/// Creates a new child host name element.
///
///
/// A new .
///
protected override ConfigurationElement CreateNewElement() {
return new HostNameElement();
}
///
/// Gets the element key for a specified configuration element.
///
/// The to return the key for.
///
/// An that acts as the key for the specified .
///
protected override object GetElementKey(ConfigurationElement element) {
Requires.NotNull(element, "element");
return ((HostNameElement)element).Name ?? string.Empty;
}
}
}