以下のようなタイプの辞書オブジェクトがあります。
Dictionary<string, Dictionary<Roles, Dictionary<Period, List<Product>>>>
アイテムとして「準備者」と「承認者」を持つ役割(列挙型)。同様に、Periodは、「Ahead」と「Past」の項目を持つ別の列挙型です。
リストには、さまざまな製品のリストが含まれています。
辞書には次の階層構造の項目があります。
"Sachin" --> Roles.Preparer --> Period.Past --> Products
"Sachin" --> Roles.Approver --> Period.Ahead --> Products
"Sachin" --> Roles.Approver --> Period.Ahead --> Products
"Sachin" --> Roles.Approver --> Period.Past --> Products
辞書を次の順序で並べ替える必要があります。
"Sachin" --> Roles.Preparer --> Period.Ahead --> Products
"Sachin" --> Roles.Approver --> Period.Ahead --> Products
"Sachin" --> Roles.Preparer --> Period.Past --> Products
"Sachin" --> Roles.Approver --> Period.Past --> Products
この構造が必要なのは、すべてのアイテムを反復処理する必要があり、メールの一部として追加する必要があるためです。
実際のコードはこんな感じです。
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Basics
{
class Product
{
public string Name { get; set; }
public int Days { get; set; }
}
enum Period
{
Ahead,
Past
}
enum Roles
{
Preparer,
Approver
}
class Program
{
static void Main(string[] args)
{
DictionaryProcessing(new string[] { "sriram123@yahoo.com", "abhishek321@yahoo.com" });
}
private static void DictionaryProcessing(string[] emailIDs)
{
List<Product> products = new List<Product>();
Product product1 = new Product() { Name = "Pencil", Days = 14 };
Product product2 = new Product() { Name = "Eraser", Days = 2 };
Product product3 = new Product() { Name = "Geometry Box", Days = 31 };
products.Add(product1);
products.Add(product2);
products.Add(product3);
Dictionary<string, Dictionary<Roles, Dictionary<Period, List<Product>>>> dict = new Dictionary<string, Dictionary<Roles, Dictionary<Period, List<Product>>>>();
///
foreach (string emailID in emailIDs)
{
if (!dict.ContainsKey(emailID))
dict.Add(emailID, new Dictionary<Roles, Dictionary<Period, List<Product>>>());
if (!dict[emailID].ContainsKey(Roles.Preparer))
dict[emailID].Add(Roles.Preparer, new Dictionary<Period, List<Product>>());
if (!dict[emailID][Roles.Preparer].ContainsKey(Period.Ahead))
dict[emailID][Roles.Preparer].Add(Period.Ahead, new List<Product>());
if (!dict[emailID][Roles.Preparer].ContainsKey(Period.Past))
dict[emailID][Roles.Preparer].Add(Period.Past, new List<Product>());
///
if (!dict[emailID].ContainsKey(Roles.Approver))
dict[emailID].Add(Roles.Approver, new Dictionary<Period, List<Product>>());
if (!dict[emailID][Roles.Approver].ContainsKey(Period.Ahead))
dict[emailID][Roles.Approver].Add(Period.Ahead, new List<Product>());
if (!dict[emailID][Roles.Approver].ContainsKey(Period.Past))
dict[emailID][Roles.Approver].Add(Period.Past, new List<Product>());
for (int i = 0; i < products.Count; i++)
{
dict[emailID][Roles.Preparer][Period.Ahead].Add(products[i]);
dict[emailID][Roles.Preparer][Period.Past].Add(products[i]);
dict[emailID][Roles.Approver][Period.Past].Add(products[i]);
dict[emailID][Roles.Approver][Period.Ahead].Add(products[i]);
}
}
}
}
}
`
この順序で並べ替えるにはどうすればよいですか?.NET2.0フレームワークの使用に制限されています。