Я бы создал собственный словарь.Примерно так:
public class TrippleKeyDict
{
private const string Separator = "<|>";
private Dictionary<string, string> _dict = new Dictionary<string, string>();
public string this[string key1, string key2, string key3]
{
get { return _dict[GetKey(key1, key2, key3)]; }
set { _dict[GetKey(key1, key2, key3)] = value; }
}
public void Add(string key1, string key2, string key3, string value)
{
_dict.Add(GetKey(key1, key2, key3), value);
}
public bool TryGetValue(string key1, string key2, string key3, out string result)
{
return _dict.TryGetValue(GetKey(key1, key2, key3), out result);
}
private static string GetKey(string key1, string key2, string key3)
{
return String.Concat(key1, Separator, key2, Separator, key3);
}
}
Если вы думаете, что объединение строк недостаточно безопасно, поскольку ключи могут содержать разделители, тогда используйте свой собственный тип ключа или Touple<string,string,string>
в качестве ключа.Поскольку эта деталь реализации скрыта в вашем пользовательском словаре, вы можете изменить его в любое время.
Вы можете использовать словарь, подобный этому
var dict = new TrippleKeyDict();
// Using the Add method
dict.Add(instanceID, templategroup, templatepart, "some value");
// Using the indexer
dict[instanceID, templategroup, templatepart] = "xy";
string result = dict[instanceID, templategroup, templatepart];
// Using the TryGetValue method
if (dict.TryGetValue(instanceID, templategroup, templatepart, out result)) {
// Do something with result
}