Я инкапсулирую словарь в свой объект. Как открыть IEnumerable > ?
Перед
class HashRunningTotalDB : Dictionary<int, SummaryEntity>
{
/...
}
// WORKS!
static void Main ()
{
HashRunningTotalDB tempDB = new HashRunningTotalDB();
//todo: load temp DB
foreach(var item in tempDB)
{
Console.Writeline(item.Key + " " + item.Value.SomeProperty);
}
}
После
class HashRunningTotalDB : IEnumerable
{
Dictionary<int, SummaryEntity> thisHashRunningTotalDB = new Dictionary<int, SummaryEntity>();
//QUESTION: HOW DO I IMPLEMENT THE GENERIC ENUMERATOR HERE?
// The following doesn't behave the same as the previous implementation
IEnumerator IEnumerable.GetEnumerator()
{
return thisHashRunningTotalDB.GetEnumerator();
}
// The following doesn't compile
Dictionary<int, SummaryEntity>.Enumerator IEnumerable<Dictionary<int, SummaryEntity>>.GetEnumerator()
{
return thisHashRunningTotalDB.GetEnumerator();
}
}
static void Main ()
{
HashRunningTotalDB tempDB = new HashRunningTotalDB();
//todo: load temp DB
// NOT WORKING
foreach(var item in tempDB)
{
Console.Writeline(item.Key + " " + item.Value.SomeProperty);
}
}