Что-то вроде этого:Возможно ли иметь словарь, где ключи имеют тип bool?
string defectGuid = null;
var dictionary = new Dictionary<bool,string> {
{new ProjectDiscrepancyWrongLocation().Conditions(row), "88ff2dfb-6190-4ab6-b13b-68de1719eac2"},
{new DestructionLeakiness().Conditions(row), "af018ee7-7974-45f8-a508-18359cde4108"},
{new CoatingInsulationDefect().Conditions(row), "232b2b2e-abc0-46b2-8b8c-45fede83ad83"},
{new CathodicProtectionUnitUnderProtectionZone().Conditions(row), "78cb3548-0d61-4809-bf28-0590dfb52010"},
{new CoatingPaintDefect().Conditions(row), "83e82b20-efc9-4500-8ca5-bb29631ccc61"},
{new ProjectDiscrepancyEdgesOffset().Conditions(row), "cf9c76c3-79eb-4856-8dc6-c9c7321a3ed5"},
{new DocumentationDiscrepancyDiscrepanciesInDocumentation().Conditions(row), "d3c793bc-5840-413a-8cae-6962772b4a88"},
{new DestructionElementDestruction().Conditions(row), "6b8924f9-5bba-4db8-b33c-099ca17a58b9"},
{new IndicatorDefectDamage().Conditions(row), "8F2560F3-31A0-4489-9A77-387BE9347D38"}
};
foreach (var item in dictionary.Where(item => item.Key)) {
defectGuid = item.Value;
}
return defectGuid;
Если один из классов выглядит следующим образом:
public class DestructionLeakiness : IDefectTypeConditions {
public bool Conditions(string[] row) {
return Helpers.NormalizeLocalizedString(row[4]).Contains("aaaa");
}
}
Вопрос в том, будет ошибка, которая говорит, что ключ уже существует.
UPDATE:
Я изменил подход к следующему:
private static string SetTypeOfDefect(string[] row)
{
string defectGuid = null;
var list = new List<Tuple<bool, string>>()
{
new Tuple<bool, string>(new ProjectDiscrepancyWrongLocation().Conditions(row), "88ff2dfb-6190-4ab6-b13b-68de1719eac2"),
new Tuple<bool, string>(new DestructionLeakiness().Conditions(row), "af018ee7-7974-45f8-a508-18359cde4108"),
new Tuple<bool, string>(new CoatingInsulationDefect().Conditions(row), "232b2b2e-abc0-46b2-8b8c-45fede83ad83"),
new Tuple<bool, string>(new CathodicProtectionUnitUnderProtectionZone().Conditions(row), "78cb3548-0d61-4809-bf28-0590dfb52010"),
new Tuple<bool, string>(new CoatingPaintDefect().Conditions(row), "83e82b20-efc9-4500-8ca5-bb29631ccc61"),
new Tuple<bool, string>(new ProjectDiscrepancyEdgesOffset().Conditions(row), "cf9c76c3-79eb-4856-8dc6-c9c7321a3ed5"),
new Tuple<bool, string>(new DocumentationDiscrepancyDiscrepanciesInDocumentation().Conditions(row), "d3c793bc-5840-413a-8cae-6962772b4a88"),
new Tuple<bool, string>(new DestructionElementDestruction().Conditions(row), "6b8924f9-5bba-4db8-b33c-099ca17a58b9"),
new Tuple<bool, string>(new IndicatorDefectDamage().Conditions(row), "8F2560F3-31A0-4489-9A77-387BE9347D38")
};
foreach (var item in list.Where(item => item.Item1))
{
defectGuid = item.Item2;
}
return defectGuid;
}
Несомненно, почему бы и нет? Ты пробовал? Что случилось? – David
Да с двумя ключами – Steve
Уверен, это возможно, но в словаре есть только два экземпляра. – Prabu