本文整理汇总了C#中Search.ClearSearchDB方法的典型用法代码示例。如果您正苦于以下问题:C# Search.ClearSearchDB方法的具体用法?C# Search.ClearSearchDB怎么用?C# Search.ClearSearchDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Search
的用法示例。
在下文中一共展示了Search.ClearSearchDB方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchAndReplaceText
/// <summary>
/// Find and replace text
/// </summary>
/// <param name="search">Searchobject with the given properties</param>
/// <param name="searchText">Text to search</param>
/// <param name="replaceText">Replacement text</param>
/// <param name="project">EPLAN Project</param>
public static void SearchAndReplaceText(Search search, string searchText, string replaceText, Project project)
{
// Init search
search.ClearSearchDB(project);
search.Project(project, searchText);
// Get objects
StorableObject[] foundObjects = search.GetAllSearchDBEntries(project);
foreach (var foundObject in foundObjects)
{
// Filter only text objects
// todo: EPLAN fix (2.6) T1085938
var existingValues = foundObject.Properties.ExistingValues
.Where(p => !p.Definition.IsInternal &&
(p.Definition.Type == PropertyDefinition.PropertyType.MultilangString ||
p.Definition.Type == PropertyDefinition.PropertyType.String)).ToList();
List<PropertyValue> existingValuesWithoutEmpty = new List<PropertyValue>();
foreach (var propertyValue in existingValues)
{
if (propertyValue.Definition.IsIndexed)
{
foreach (int index in propertyValue.Indexes)
{
if (!propertyValue[index].IsEmpty)
{
existingValuesWithoutEmpty.Add(propertyValue[index]);
}
}
}
else
{
if (!propertyValue.IsEmpty)
{
existingValuesWithoutEmpty.Add(propertyValue);
}
}
}
existingValues = existingValuesWithoutEmpty;
// Replace
foreach (PropertyValue propertyValue in existingValues)
{
switch (propertyValue.Definition.Type)
{
// MultiLanguageString
case PropertyDefinition.PropertyType.MultilangString:
MultiLangString multiLangString = propertyValue;
var valueMultiLangString = multiLangString.GetAsString();
if (valueMultiLangString.Contains(searchText))
{
string newValue = valueMultiLangString.Replace(searchText, replaceText); // All languages
multiLangString.SetAsString(newValue);
propertyValue.Set(newValue);
}
break;
// String
case PropertyDefinition.PropertyType.String:
var value = propertyValue.ToString();
if (value.Contains(searchText))
{
string newValue = value.Replace(searchText, replaceText);
propertyValue.Set(newValue);
}
break;
}
}
}
}