17 using System.Collections;
18 using System.Collections.Generic;
20 using erminas.SmartAPI.CMS;
22 namespace erminas.SmartAPI.Utils.CachedCollections
24 public interface IRDEnumerable<T> : IEnumerable<T> where T : class,
IRedDotObject
26 bool Contains(T element);
27 bool ContainsGuid(Guid guid);
28 bool ContainsName(
string name);
31 T GetByGuid(Guid guid);
36 T GetByName(
string name);
38 bool TryGetByGuid(Guid guid, out T output);
44 bool TryGetByName(
string name, out T output);
47 internal static class RDEnumerableWrapper
49 internal static IRDEnumerable<T> ToRDEnumerable<T>(
this IEnumerable<T> enumerable)
52 return new RDEnumerable<T>(enumerable);
56 internal class RDEnumerable<T> : IRDEnumerable<T> where T : class,
IRedDotObject
58 private readonly IEnumerable<T> _wrappedList;
60 internal RDEnumerable(IEnumerable<T> wrappedList)
62 _wrappedList = wrappedList.ToList();
65 public bool Contains(T element)
67 return _wrappedList.Contains(element);
70 public bool ContainsGuid(Guid guid)
72 return _wrappedList.Any(arg => arg.Guid == guid);
75 public bool ContainsName(
string name)
77 return _wrappedList.Any(arg => arg.Name == name);
82 get {
return _wrappedList.Count(); }
85 public T GetByGuid(Guid guid)
87 return _wrappedList.First(arg => arg.Guid == guid);
90 public T GetByName(
string name)
92 return _wrappedList.First(arg => arg.Name == name);
95 public IEnumerator GetEnumerator()
97 return ((IEnumerable) _wrappedList).GetEnumerator();
100 public bool TryGetByGuid(Guid guid, out T output)
102 output = _wrappedList.FirstOrDefault(arg => arg.Guid == guid);
103 return output != null;
106 public bool TryGetByName(
string name, out T output)
108 output = _wrappedList.FirstOrDefault(arg => arg.Name == name);
109 return output != null;
112 IEnumerator<T> IEnumerable<T>.GetEnumerator()
114 return _wrappedList.GetEnumerator();