//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging { using System; using System.Collections.ObjectModel; using Validation; /// /// A KeyedCollection whose item -> key transform is provided via a delegate /// to its constructor, and null items are disallowed. /// /// The type of the key. /// The type of the item. [Serializable] internal class KeyedCollectionDelegate : KeyedCollection { /// /// The delegate that returns a key for the given item. /// private Func getKeyForItemDelegate; /// /// Initializes a new instance of the KeyedCollectionDelegate class. /// /// The delegate that gets the key for a given item. internal KeyedCollectionDelegate(Func getKeyForItemDelegate) { Requires.NotNull(getKeyForItemDelegate, "getKeyForItemDelegate"); this.getKeyForItemDelegate = getKeyForItemDelegate; } /// /// When implemented in a derived class, extracts the key from the specified element. /// /// The element from which to extract the key. /// The key for the specified element. protected override TKey GetKeyForItem(TItem item) { ErrorUtilities.VerifyArgumentNotNull(item, "item"); // null items not supported. return this.getKeyForItemDelegate(item); } } }