/// <summary> /// Проверяет, влючена ли буква в данный алфавит. /// </summary> /// <param name="findLatter">буква</param> /// <returns></returns> public bool Contains(Letter findLatter) { foreach (Letter letter in Letters) { if (letter == findLatter) return true; } return false; }
public static Machine Deserialize(string fileName) { Machine machine = new Machine(); XmlDocument xml = new XmlDocument(); xml.Load(fileName); XmlElement xmlMachine = xml["machine"]; var states = xmlMachine["States"]; foreach (XmlElement xmlState in states) { State state = new State(); var attributes = xmlState.Attributes; state.Name = attributes[0].Value; state.IsLast = Convert.ToBoolean(attributes[1].Value); machine.States.Add(state); } var letters = xmlMachine["Alphabet"]; foreach (XmlElement xmlLetter in letters) { Letter letter = new Letter(); var attributes = xmlLetter.Attributes; letter.Name = attributes[0].Value; letter.Description = attributes[1].Value; machine.Alphabet.Letters.Add(letter); } var functions = xmlMachine["Functions"]; foreach (XmlElement xmlFunction in functions) { Function function = new Function(); var attributes = xmlFunction.Attributes; function.Name = attributes[0].Value; function.From = machine.States.Where(n => n.Name == attributes[1].Value).ToList()[0]; function.To = machine.States.Where(n => n.Name == attributes[2].Value).ToList()[0]; function.Letter = machine.Alphabet.Letters.Where(n => n.Name == attributes[3].Value).ToList()[0]; machine.Functions.Add(function); } try { var firstState = xmlMachine.LastChild; var stateName = firstState.Attributes[0].Value; machine.FirstState = machine.States.Where(n => n.Name == stateName).ToList()[0]; } catch { machine.FirstState = null; } return machine; }
private void AddNewLetter(object sender, EventArgs e) { try { string letterName = LetterName.Text; string letterDescription = LetterDescription.Text; Letter letter = new Letter(letterName, letterDescription); machine.Alphabet.AddNewLetter(letter); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка!"); } }
/// <summary> /// Добавляет новую букву в алфавит. /// </summary> /// <param name="letter">буква</param> public void AddNewLetter(Letter newLetter) { if (newLetter.Name.Length > 0) { foreach (Letter letter in letters) { if (letter == newLetter) throw new ArgumentException("Такая буква уже есть!"); } letters.Add(newLetter); } else { throw new ArgumentException("Таконе название не допустимо!"); } }
public void removeLetter(Letter letter) { for (int i = 0; i < functions.Count; i++) { if (functions[i].Letter == letter) { removeFunction(functions[i]); i--; } } alphabet.Letters.Remove(letter); }
public Function(string name, State from, State to, Letter letter) { this.name = name; this.from = from; this.to = to; this.letter = letter; }
public Function() { this.name = ""; this.from = new State(); this.to = new State(); this.letter = new Letter(); }