Skip to content

Instantly share code, notes, and snippets.

@5up3rman
Last active October 12, 2016 13:51
Show Gist options
  • Save 5up3rman/d4ac4c0ae9fa57d318e73d2047bda0f8 to your computer and use it in GitHub Desktop.
Save 5up3rman/d4ac4c0ae9fa57d318e73d2047bda0f8 to your computer and use it in GitHub Desktop.
MappedItemExtensions
public static class MappedItemExtensions
{
public static IMappedItem GetMappedItem(IEnumerable<IMappedItem> mappedItems, MappedItemType itemType, string originalName)
{
return mappedItems.FirstOrDefault(x => x.OriginalName.EndsWith(originalName) && x.Type.Equals(itemType));
}
public static IEnumerable<T> AddOrReplaceItem<T>(this List<T> list, T item) where T : IMappedItem
{
var idx = list.FindIndex(x => x.OriginalName.Equals(item.OriginalName));
if (idx.Equals(-1))
list.Add(item);
else
list[idx] = item;
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment