public override object Execute(FiMClass reportClass) { if (!this.Complete) { throw new FiMException("Executing an incomplete switch statement"); } var variable = reportClass.GetVariable(this.RawVariable); if (variable == null) { throw new FiMException("Varible " + this.RawVariable + " does not exist"); } if (FiMHelper.IsTypeArray(variable)) { throw new FiMException("Cannot use array on a switch"); } Dictionary <object, string> CasesLookup = new Dictionary <object, string>(); foreach (var key in Cases.Keys) { if (!KirinSwitchCase.IsValidPlace(key, reportClass, out object value)) { throw new FiMException("Invalid case " + key); } if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, value))) { throw new FiMException("Duplicate case value " + key); } CasesLookup.Add(value, key); } KirinStatement s = DefaultCase; if (CasesLookup.Keys.Any(k => KirinValue.IsEqual(k, variable.Value))) { s = Cases[CasesLookup.First(l => KirinValue.IsEqual(l.Key, variable.Value)).Value]; } if (s != null) { return(s.Execute(reportClass)); } return(null); }
public static bool IsEqual(KirinValue x, KirinValue y) => KirinValue.IsEqual(x.Value, y.Value);