множественные замены с параметром

This commit is contained in:
melekhin
2026-09-10 15:53:51 +07:00
parent eb3055a2e8
commit 70a19ad738
3 changed files with 621 additions and 25 deletions
+52 -24
View File
@@ -344,7 +344,7 @@ internal sealed class WordWriter : WordReader, IWordWriter
#region динамические змены с параметром
public void ReplaceString(string oldValue, Func<string, string> newValues)
{
@@ -373,7 +373,6 @@ internal sealed class WordWriter : WordReader, IWordWriter
_isModified = true;
}
}
public void ReplaceItem(string oldValue, Func<string, ReplaceItem> newValues)
{
ThrowIfDisposed();
@@ -401,7 +400,6 @@ internal sealed class WordWriter : WordReader, IWordWriter
_isModified = true;
}
}
public void ReplaceToText(string oldValue, Action<string, IText> buildText)
{
ThrowIfDisposed();
@@ -422,45 +420,75 @@ internal sealed class WordWriter : WordReader, IWordWriter
}
}
public void ReplaceString(string oldValue, Func<string, string[]> newValues)
=> ReplaceString(oldValue, (Func<string, IEnumerable<string>>)newValues);
public void ReplaceString(string oldValue, Func<string, IEnumerable<string>> newValues)
{
throw new NotImplementedException();
}
ThrowIfDisposed();
public void ReplaceString(string oldValue, Func<string, string[]> newValues)
{
throw new NotImplementedException();
}
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (newValues is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceString(dynamic-multi)] START: '{oldValue}'");
#endif
lock (_syncLock)
{
// 1. Основной текст
DynamicMultiReplaceExt.ReplaceStringMultiInBody(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 2. Таблицы в основном тексте
DynamicMultiReplaceExt.ReplaceStringMultiInTables(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 3. Колонтитулы
DynamicMultiReplaceExt.ReplaceStringMultiInHeadersFooters(_doc, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
_isModified = true;
}
}
public void ReplaceItem(string oldValue, Func<string, ReplaceItem[]> newValues)
=> ReplaceItem(oldValue, (Func<string, IEnumerable<ReplaceItem>>)newValues);
public void ReplaceItem(string oldValue, Func<string, IEnumerable<ReplaceItem>> newValues)
{
throw new NotImplementedException();
}
ThrowIfDisposed();
public void ReplaceItem(string oldValue, Func<string, ReplaceItem[]> newValues)
{
throw new NotImplementedException();
if (string.IsNullOrEmpty(oldValue))
throw new ArgumentException("Old value cannot be null or empty", nameof(oldValue));
if (newValues is null) return;
#if DEBUG
Debug.WriteLine($"[DEBUG] [WordProcessor.ReplaceItem(dynamic-multi)] START: '{oldValue}'");
#endif
lock (_syncLock)
{
// 1. Основной текст
DynamicMultiReplaceExt.ReplaceItemMultiInBody(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 2. Таблицы в основном тексте
DynamicMultiReplaceExt.ReplaceItemMultiInTables(_body, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
// 3. Колонтитулы
DynamicMultiReplaceExt.ReplaceItemMultiInHeadersFooters(_doc, oldValue, newValues, StringComparison.OrdinalIgnoreCase);
_isModified = true;
}
}
public void ReplaceToTable(string oldValue, Action<string, ITable> buildTable)
{
throw new NotImplementedException();
}
public void ReplaceToTable(string oldValue, FontProps baseFont, Action<string, ITable> buildTable)
{
throw new NotImplementedException();
}
#endregion