public void ReadXml(XmlReader reader) { reader.MoveToContent(); var typeString = reader.GetAttribute("type"); if (typeString is null) { throw new InvalidOperationException($"Invalid {nameof(Phoneme)} XML: Expected type attribute"); } if (!Enum.TryParse <PhonemeType>(typeString, true, out var type)) { throw new InvalidOperationException($"Invalid {nameof(Phoneme)} XML: Invalid type attribute. Expected one of [{string.Join(", ", Enum.GetNames(typeof(PhonemeType)))}]"); } Type = type; reader.ReadStartElement(); Value = reader.ReadElementContentAsString("Value", ""); if (reader.NodeType != XmlNodeType.EndElement) { ExampleWord = new PhonemeExample(); ExampleWord.ReadXml(reader); ExampleTranscription = reader.ReadElementContentAsString("ExampleTranscription", ""); } if (reader.NodeType != XmlNodeType.EndElement) { Description = reader.ReadElementContentAsString("Description", ""); } reader.ReadEndElement(); }
public Phoneme(PhonemeType type, string value, PhonemeExample exampleWord, string exampleTranscription, string description) { Type = type; Value = value; if (exampleWord != null) { if (exampleTranscription is null) { throw new ArgumentNullException(nameof(exampleTranscription), $"{nameof(exampleTranscription)} cannot be null if {nameof(exampleWord)} is not null."); } ExampleWord = exampleWord; ExampleTranscription = exampleTranscription; } Description = description; }
public Phoneme(PhonemeType type, string value, PhonemeExample exampleWord, string exampleTranscription) : this(type, value, exampleWord, exampleTranscription, string.Empty) { }