namespace QWERTYkez.WordProcessor; internal static class Extension { public static void SwapBottomRight(this PageMargin margin) { if (margin.Right is { } r) { margin.Right = margin.Bottom is not null ? new((uint)margin.Bottom.Value) : null; margin.Bottom = new((int)r.Value); } else if(margin.Bottom is { } b) { margin.Bottom = null; margin.Right = new((uint)b.Value); } } public static void SwapValues(this PageSize size) { if (size.Width is { } w) { size.Width = size.Height is not null ? new(size.Height.Value) : null; size.Height = new(w.Value); } else if (size.Height is { } h) { size.Height = null; size.Width = new(h.Value); } } /// /// Возвращает индекс указанного элемента в коллекции. /// /// Коллекция элементов. /// Элемент для поиска. /// Индекс элемента, или -1, если элемент не найден. public static int IndexOf(this OpenXmlElementList list, OpenXmlElement element) { if (list == null || element == null) return -1; for (int i = 0; i < list.Count; i++) { if (list[i] == element) return i; } return -1; } }