public static List <FileIndexItem> SearchAndReplace(List <FileIndexItem> fileIndexResultsList, string fieldName, string search, string replace) { foreach (var fileIndexItem in fileIndexResultsList.Where( p => p.Status == FileIndexItem.ExifStatus.Ok || p.Status == FileIndexItem.ExifStatus.Deleted)) { var searchInObject = FileIndexCompareHelper.Get(fileIndexItem, fieldName); var replacedToObject = new object(); PropertyInfo[] propertiesA = new FileIndexItem().GetType().GetProperties( BindingFlags.Public | BindingFlags.Instance); PropertyInfo property = propertiesA.FirstOrDefault(p => string.Equals( p.Name, fieldName, StringComparison.InvariantCultureIgnoreCase)); if (property.PropertyType == typeof(string)) { var searchIn = ( string )searchInObject; // Replace Ignore Case replacedToObject = Regex.Replace( searchIn, Regex.Escape(search), replace.Replace("$", "$$"), RegexOptions.IgnoreCase ); } // only string types are added here, other types are ignored for now FileIndexCompareHelper.Set(fileIndexItem, fieldName, replacedToObject); } return(fileIndexResultsList); }
public void FileIndexCompareHelperTest__SetValue_WrongTypeCast() { // wrong types are ignored by default Assert.AreEqual(string.Empty, FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags), 1).Tags); }
public void FileIndexCompareHelperTest__SetValue_UnknownValue() { // try database type that does not exist Assert.AreEqual(string.Empty, FileIndexCompareHelper.Set(null, "ThisTagDoesNotExist", "value").Tags); }
public void FileIndexCompareHelperTest__SetValue_Tags_LowerCase() { Assert.AreEqual("value", FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags).ToLowerInvariant(), "value").Tags); }
public void FileIndexCompareHelperTest__SetValue_Tags() { Assert.AreEqual("value", FileIndexCompareHelper.Set(null, nameof(FileIndexItem.Tags), "value").Tags); }