using System.IO; using System.Text; using System.Xml; namespace AIPractice.Shared.Labels { /// /// 结论恶性程度 /// public enum MalignantLevel { /// /// 正常 /// Low = 0, /// /// 中度 /// Middle = 1, /// /// 恶性 /// High = 2 } public class ConclusionLabel: ImageLabel { /// /// Gets the MalignantLevel of this Conclusion. /// public MalignantLevel Level { get; set; } /// /// Gets or sets if this label is the parts label. /// public bool IsParts { get; set; } /// /// Gets or sets if this label is unique label of its root. /// public bool IsUnique { get; set; } public ConclusionLabel(string id, string title, MalignantLevel level) : base(id, title) { Level = level; } public static ConclusionLabel FromXml(string xmlContent) { using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(xmlContent))) { using (var r = XmlReader.Create(ms)) { r.Read(); var id = r.GetAttribute("id"); var title = r.GetAttribute("title"); var malignantLevelStr = r.GetAttribute("malignantLevel"); var malignantLevel = MalignantLevel.Low; if (int.TryParse(malignantLevelStr, out int m)) { malignantLevel = (MalignantLevel)m; } var isPartsStr = r.GetAttribute("isParts"); bool.TryParse(isPartsStr, out var isParts); var isUniqueStr = r.GetAttribute("isUnique"); bool.TryParse(isUniqueStr, out var isUnique); return new ConclusionLabel(id, title, malignantLevel) { IsParts = isParts, IsUnique = isUnique }; } } } public override string ToXml() { return $"<{nameof(ConclusionLabel)} id=\"{Id}\" title=\"{Title}\" malignantLevel=\"{(int)Level}\" isParts=\"{IsParts}\" isUnique=\"{IsUnique}\"/>"; } } }