Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Eremite.Model;
- using System.Collections.Generic;
- using System.Linq;
- namespace HLive
- {
- public static class IdentifiableExtensions
- {
- public static T GetById<T>(this IList<T> list, int id) where T : IIdentifiable
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].Id == id)
- return list[i];
- return default;
- }
- public static bool ContainsId<T>(this IList<T> list, int id) where T : IIdentifiable
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].Id == id)
- return true;
- return false;
- }
- public static bool ContainsDuplicates<T>(this IList<T> list) where T : IIdentifiable
- {
- return list.GroupBy(x => x.Id).Any(g => g.Count() > 1);
- }
- public static IEnumerable<IGrouping<int, T>> GetDuplicates<T>(this IList<T> list) where T : IIdentifiable
- {
- return list.GroupBy(x => x.Id).Where(g => g.Count() > 1);
- }
- }
- public static class IdentifiableStateExtensions
- {
- public static T GetByUniqueId<T>(this IList<T> list, int uniqueId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].UniqueId == uniqueId)
- return list[i];
- return default;
- }
- public static bool ContainsUniqueId<T>(this IList<T> list, int uniqueId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].UniqueId == uniqueId)
- return true;
- return false;
- }
- public static void RemoveByUniqueId<T>(this IList<T> list, int uniqueId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].UniqueId == uniqueId)
- list.RemoveAt(i);
- }
- public static T GetByModelId<T>(this IList<T> list, int modelId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].ModelId == modelId)
- return list[i];
- return default;
- }
- public static bool ContainsModelId<T>(this IList<T> list, int modelId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].ModelId == modelId)
- return true;
- return false;
- }
- public static void RemoveByModelId<T>(this IList<T> list, int modelId) where T : IIdentifiableState
- {
- int count = list.Count;
- for (int i = 0; i < count; i++)
- if (list[i].ModelId == modelId)
- list.RemoveAt(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement