Files
QWERTYkez.OpenXmlProcessors/QWERTYkez.WordProcessor/Extension.cs
T
2026-09-07 15:52:23 +07:00

51 lines
1.5 KiB
C#

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);
}
}
/// <summary>
/// Возвращает индекс указанного элемента в коллекции.
/// </summary>
/// <param name="list">Коллекция элементов.</param>
/// <param name="element">Элемент для поиска.</param>
/// <returns>Индекс элемента, или -1, если элемент не найден.</returns>
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;
}
}