private void Validate() { Errors.Clear(); for (int i = 0; i < BaseUnits.Count; i++) { for (int j = i + 1; j < BaseUnits.Count; j++) { if (BaseUnits[i].name == BaseUnits[j].name) { Errors.Add("Repeated base unit " + BaseUnits[i].name); } } for (int j = 0; j < DerivedUnits.Count; j++) { if (BaseUnits[i].name == DerivedUnits[j].name) { Errors.Add("Base and derived unit conflict " + BaseUnits[i].name); } } if (BaseUnits[i].name.ToLower() == "e") { Errors.Add("Base unit cannot be 'e' or 'E'"); } } for (int i = 0; i < DerivedUnits.Count; i++) { for (int j = i + 1; j < DerivedUnits.Count; j++) { if (DerivedUnits[i].name == DerivedUnits[j].name) { Errors.Add("Repeated derived unit " + DerivedUnits[i].name); } } if (DerivedUnits[i].name.ToLower() == "e") { Errors.Add("Derived unit cannot be 'e' or 'E'"); } } for (int i = 0; i < Prefixes.Count; i++) { for (int j = i + 1; j < Prefixes.Count; j++) { if (Prefixes.ElementAt(i).Key == Prefixes.ElementAt(j).Key) { Errors.Add("Repeated prefix " + Prefixes.ElementAt(i).Key); } } for (int j = 0; j < Constants.Count; j++) { if (Prefixes.ElementAt(i).Key == Constants[j].name) { Errors.Add("Prefix and constant conflict " + Prefixes.ElementAt(i).Key); } } } for (int i = 0; i < Constants.Count; i++) { for (int j = i + 1; j < Constants.Count; j++) { if (Constants[i].name == Constants[j].name) { Errors.Add("Repeated constant " + Constants[i].name); } } } foreach (KeyValuePair <string, double> kvp in Prefixes) { if (kvp.Key.Length > 1) { foreach (BaseUnit check in BaseUnits) { if (check.name.Contains(kvp.Key)) { Errors.Add("Prefix and base unit conflict " + kvp.Key + " " + check.name); } } foreach (DerivedUnit check in DerivedUnits) { if (check.name.Contains(kvp.Key)) { Errors.Add("Prefix and base unit conflict " + kvp.Key + " " + check.name); } } foreach (Constant check in Constants) { if (check.name.Contains(kvp.Key)) { Errors.Add("Prefix and constant conflict " + kvp.Key + " " + check.name); } } } } if (Errors.Count > 0) { foreach (string error in Errors) { Microsoft.SmallBasic.Library.TextWindow.WriteLine(error); } } SetDimensions(); foreach (DerivedUnit unit in DerivedUnits) { Errors.Clear(); Leaf fromLeaf = new Leaf(eOperatorType.MULTIPLY, eLeafType.COMPOUND, unit.name); foreach (string error in Errors) { Microsoft.SmallBasic.Library.TextWindow.WriteLine(error); } } }