Skip to content

Commit 7d13929

Browse files
committed
[SchemaValidator] Add error for switch field not found to ConditionRefValidator as well
1 parent 609c2ee commit 7d13929

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

SchemaValidator/Validation/Validators/ConditionRefValidator.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using EXDCommon;
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using EXDCommon;
24
using EXDCommon.FileAccess;
35
using EXDCommon.SchemaModel.EXDSchema;
46
using EXDCommon.Sheets;
@@ -59,7 +61,16 @@ public override ValidationResults Validate(ExcelHeaderFile exh, Sheet sheet)
5961
{
6062
var offset = field.Definition.Offset;
6163
var switchOn = field.Field.Condition.Switch;
62-
var switchField = fields.First(f => f.Field.Name == switchOn);
64+
var switchFields = fields.Where(f => f.Field.Name == switchOn).ToList();
65+
66+
if (!switchFields.Any())
67+
{
68+
var msg = $"Column {field.Field.Name}@0x{offset:X} type {field.Definition.Type} has switch {switchOn} but no field by that name was found.";
69+
results.Results.Add(ValidationResult.Failed(sheet.Name, ValidatorName(), msg));
70+
continue;
71+
}
72+
73+
var switchField = switchFields[0];
6374
// var definedSwitchColumnValues = field.Field.Condition.Cases.Keys.ToHashSet();
6475

6576
// store the column values for each switch value

0 commit comments

Comments
 (0)