У меня есть статический класс для хранения словаря и 2 метода получения доступа к нему.
Вот мой класс:
public static class ConfiguraCuadros
{
public static Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,string>>>> GetDictionary()
{
// Try to get the result in the static Dictionary
return _configcuadros;
}
public static Dictionary<string, Dictionary<string, Dictionary<string, string>>> GetHoja(string key)
{
// Try to get the result in the static Dictionary
Dictionary<string, Dictionary<string, Dictionary<string, string>>> result = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
if (_configcuadros.TryGetValue(key, out result))
{
return result;
}
else
{
return null;
}
}
public static readonly Dictionary<string, Dictionary<string, Dictionary<string, Dictionary<string, string>>>> _configcuadros = new Dictionary<string, Dictionary<string, Dictionary<string, Dictionary<string, string>>>>
{
{ "Formato01", //this is just a hint, the dictionary is much more extensive
new Dictionary<string, Dictionary<string, Dictionary<string, string>>>
{
{
"F01C01A",
new Dictionary<string, Dictionary<string, string>>
{
{
"X",
new Dictionary<string, string>
{
{ "key1" , "value1" },
{ "key2" , "value2" },
{ "key3" , "value3" },
}
},
}
},
}
},
}
}`
Когда я использую метод получения,
ConfiguraCuadros.GetDictionary();
Выдает исключение:
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll 'ConfiguraCuadros.GetDictionary()' threw an exception of type 'System.TypeInitializationException' base: {"The type initializer for 'beDGRAIC.ConfiguraCuadros' threw an exception."} TypeName: "beDGRAIC.ConfiguraCuadros"
or
'ConfiguraCuadros.GetHoja("Formato01")' threw an exception of type 'System.TypeInitializationException' base: {"The type initializer for 'beDGRAIC.ConfiguraCuadros' threw an exception."} TypeName: "beDGRAIC.ConfiguraCuadros"
Как видите, я намерен создать статический словарь. Я думаю, что проблема в объявлении словаря... но я не вижу, где...
На всякий случай, "beDGRAIC" - это мое пространство имен.
Спасибо за вашу помощь!
Tuple
вместо многоуровневого вложенногоDictionary
- person Shiva   schedule 29.10.2014Dictionary<string,Dictionary<string,Dictionary<string,Dictionary<string,string>>>>
? Прежде чем исправлятьTypeInitializationException
, подумайте о хорошей структуре данных. - person Sriram Sakthivel   schedule 29.10.2014