, DoSomethingWithCollection - 1) ICollection/IEnumerable, . 2) , . .
: , .
delegate void KeyValueItemParser(object item, out string key, out string value);
void DoSomethingWithCollection(ICollection items, KeyValueItemParser parser)
{
string key, value
foreach(object item in items)
{
parser(item, out key, out value);
}
}
. 2: , . DoSomethingWithCollection, - , - . . - , / NamedValuePair/KeyValuePair, -, .
interface IKeyValuePairCollection
{
int Count {get; }
KeyValuePair<string, string> Item(int index) { get; }
}
class NamedValueCollectionWrapper : IKeyValuePairCollection
{
private NamedValueCollection _inner;
public NamedValueCollectionWrapper(NamedValueCollection target)
{
-inner = target;
}
}
class KeyValueConfigurationCollectionWrapper : IKeyValuePairCollection
{
...
}
IMO, .