Created
February 8, 2024 15:11
-
-
Save bjoerntx/96a5a590551dcdbd15ca58656192a90e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TXTextControl.DocumentServer.Fields; | |
namespace TXTextControl.DocumentServer.DataSources | |
{ | |
public static class Refactor | |
{ | |
public static void RenameDataColumn(TextControl textControl, | |
string oldColumnName, | |
string newColumnName) | |
{ | |
// iterate through all TextParts | |
foreach (TextPartBase textPart in textControl.TextParts) | |
{ | |
RenameMergeBlocks(textPart.SubTextParts, oldColumnName, newColumnName); | |
RenameMergeFields(textPart.ApplicationFields, oldColumnName, newColumnName); | |
} | |
} | |
private static void RenameMergeBlocks(SubTextPartCollection subTextParts, | |
string oldColumnName, | |
string newColumnName) | |
{ | |
// iterate through all SubTextParts | |
foreach (SubTextPart subTextPart in subTextParts) | |
{ | |
// check if the SubTextPart is a merge block | |
if (subTextPart.Name == "txmb_" + oldColumnName) | |
{ | |
// rename the SubTextPart | |
subTextPart.Name = "txmb_" + newColumnName; | |
} | |
} | |
} | |
private static void RenameMergeFields(ApplicationFieldCollection applicationFields, | |
string oldColumnName, | |
string newColumnName) | |
{ | |
// iterate through all ApplicationFields | |
foreach (ApplicationField applicationField in applicationFields) | |
{ | |
// check if the ApplicationField is a merge field and contains the old column name | |
if (applicationField.TypeName == "MERGEFIELD" && | |
applicationField.Name.Contains(oldColumnName)) | |
{ | |
// create a new MergeField object and replace the old column name with the new column name | |
MergeField mergeField = new MergeField(applicationField); | |
mergeField.Name = mergeField.Name.Replace(oldColumnName, newColumnName); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment