mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-31 07:51:36 +00:00 
			
		
		
		
	.Net 6 Upgrade
This commit is contained in:
		| @@ -30,245 +30,244 @@ using System.Collections; | ||||
| using Esiur.Core; | ||||
| using System.Reflection; | ||||
|  | ||||
| namespace Esiur.Data | ||||
| namespace Esiur.Data; | ||||
|  | ||||
| public class ResourceList<T, ST> : IEnumerable<T>, ICollection, ICollection<T> | ||||
| { | ||||
|     public class ResourceList<T, ST> : IEnumerable<T>, ICollection, ICollection<T> | ||||
|  | ||||
|     private readonly object syncRoot = new object(); | ||||
|     private List<T> list = new List<T>(); | ||||
|  | ||||
|     public delegate void Modified(ST sender, int index, T oldValue, T newValue); | ||||
|     public delegate void Added(ST sender, T value); | ||||
|     public delegate void Removed(ST sender, int index, T value); | ||||
|     public delegate void Cleared(ST sender); | ||||
|  | ||||
|  | ||||
|     public event Modified OnModified; | ||||
|     public event Removed OnRemoved; | ||||
|     public event Cleared OnCleared; | ||||
|     public event Added OnAdd; | ||||
|  | ||||
|     ST state; | ||||
|  | ||||
|     public void Sort() | ||||
|     { | ||||
|         list.Sort(); | ||||
|     } | ||||
|  | ||||
|         private readonly object syncRoot = new object(); | ||||
|         private List<T> list = new List<T>(); | ||||
|     public void Sort(IComparer<T> comparer) | ||||
|     { | ||||
|         list.Sort(comparer); | ||||
|     } | ||||
|  | ||||
|         public delegate void Modified(ST sender, int index, T oldValue, T newValue); | ||||
|         public delegate void Added(ST sender, T value); | ||||
|         public delegate void Removed(ST sender, int index, T value); | ||||
|         public delegate void Cleared(ST sender); | ||||
|     public void Sort(Comparison<T> comparison) | ||||
|     { | ||||
|         list.Sort(comparison); | ||||
|     } | ||||
|  | ||||
|     public IEnumerable<T> Where(Func<T, bool> predicate) | ||||
|     { | ||||
|         return list.Where(predicate); | ||||
|     } | ||||
|  | ||||
|         public event Modified OnModified; | ||||
|         public event Removed OnRemoved; | ||||
|         public event Cleared OnCleared; | ||||
|         public event Added OnAdd; | ||||
|     /// <summary> | ||||
|     /// Convert AutoList to array | ||||
|     /// </summary> | ||||
|     /// <returns>Array</returns> | ||||
|     public T[] ToArray() | ||||
|     { | ||||
|         //    list.OrderBy() | ||||
|         return list.ToArray(); | ||||
|     } | ||||
|  | ||||
|         ST state; | ||||
|     /// <summary> | ||||
|     /// Create a new instance of AutoList | ||||
|     /// </summary> | ||||
|     /// <param name="state">State object to be included when an event is raised.</param> | ||||
|     public ResourceList(ST state) | ||||
|     { | ||||
|         this.state = state; | ||||
|     } | ||||
|  | ||||
|         public void Sort() | ||||
|     /// <summary> | ||||
|     /// Create a new instance of AutoList | ||||
|     /// </summary> | ||||
|     /// <param name="values">Populate the list with items</param> | ||||
|     /// <returns></returns> | ||||
|     public ResourceList(ST state, T[] values) | ||||
|     { | ||||
|         this.state = state; | ||||
|         AddRange(values); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Synchronization lock of the list | ||||
|     /// </summary> | ||||
|     public object SyncRoot | ||||
|     { | ||||
|         get | ||||
|         { | ||||
|             list.Sort(); | ||||
|         } | ||||
|  | ||||
|         public void Sort(IComparer<T> comparer) | ||||
|         { | ||||
|             list.Sort(comparer); | ||||
|         } | ||||
|  | ||||
|         public void Sort(Comparison<T> comparison) | ||||
|         { | ||||
|             list.Sort(comparison); | ||||
|         } | ||||
|  | ||||
|         public IEnumerable<T> Where(Func<T, bool> predicate) | ||||
|         { | ||||
|             return list.Where(predicate); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Convert AutoList to array | ||||
|         /// </summary> | ||||
|         /// <returns>Array</returns> | ||||
|         public T[] ToArray() | ||||
|         { | ||||
|             //    list.OrderBy() | ||||
|             return list.ToArray(); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Create a new instance of AutoList | ||||
|         /// </summary> | ||||
|         /// <param name="state">State object to be included when an event is raised.</param> | ||||
|         public ResourceList(ST state) | ||||
|         { | ||||
|             this.state = state; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Create a new instance of AutoList | ||||
|         /// </summary> | ||||
|         /// <param name="values">Populate the list with items</param> | ||||
|         /// <returns></returns> | ||||
|         public ResourceList(ST state, T[] values) | ||||
|         { | ||||
|             this.state = state; | ||||
|             AddRange(values); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Synchronization lock of the list | ||||
|         /// </summary> | ||||
|         public object SyncRoot | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return syncRoot; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// First item in the list | ||||
|         /// </summary> | ||||
|         public T First() | ||||
|         { | ||||
|             return list.First(); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Get an item at a specified index | ||||
|         /// </summary> | ||||
|         public T this[int index] | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 return list[index]; | ||||
|             } | ||||
|             set | ||||
|             { | ||||
|                 var oldValue = list[index]; | ||||
|  | ||||
|                 lock (syncRoot) | ||||
|                     list[index] = value; | ||||
|  | ||||
|                 OnModified?.Invoke(state, index, oldValue, value); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Add item to the list | ||||
|         /// </summary> | ||||
|         public void Add(T value) | ||||
|         { | ||||
|             lock (syncRoot) | ||||
|                 list.Add(value); | ||||
|  | ||||
|             OnAdd?.Invoke(state, value); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Add an array of items to the list | ||||
|         /// </summary> | ||||
|         public void AddRange(T[] values) | ||||
|         { | ||||
|             foreach (var v in values) | ||||
|                 Add(v); | ||||
|         } | ||||
|  | ||||
|         private void ItemDestroyed(object sender) | ||||
|         { | ||||
|             Remove((T)sender); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Clear the list | ||||
|         /// </summary> | ||||
|         public void Clear() | ||||
|         { | ||||
|  | ||||
|             lock (syncRoot) | ||||
|                 list.Clear(); | ||||
|  | ||||
|             OnCleared?.Invoke(state); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Remove an item from the list | ||||
|         /// <param name="value">Item to remove</param> | ||||
|         /// </summary> | ||||
|         public void Remove(T value) | ||||
|         { | ||||
|             var index = 0; | ||||
|  | ||||
|             lock (syncRoot) | ||||
|             { | ||||
|                 index = list.IndexOf(value); | ||||
|  | ||||
|                 if (index == -1) | ||||
|                     return; | ||||
|  | ||||
|                 list.RemoveAt(index); | ||||
|  | ||||
|  | ||||
|             } | ||||
|  | ||||
|             OnRemoved?.Invoke(state, index, value); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Number of items in the list | ||||
|         /// </summary> | ||||
|         public int Count | ||||
|         { | ||||
|             get { return list.Count; } | ||||
|         } | ||||
|  | ||||
|         public bool IsSynchronized => (list as ICollection).IsSynchronized; | ||||
|  | ||||
|         public bool IsReadOnly => throw new NotImplementedException(); | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Check if an item exists in the list | ||||
|         /// </summary> | ||||
|         /// <param name="value">Item to check if exists</param> | ||||
|         public bool Contains(T value) | ||||
|         { | ||||
|             return list.Contains(value); | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Check if any item of the given array is in the list | ||||
|         /// </summary> | ||||
|         /// <param name="values">Array of items</param> | ||||
|         public bool ContainsAny(T[] values) | ||||
|         { | ||||
|             foreach (var v in values) | ||||
|                 if (list.Contains(v)) | ||||
|                     return true; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Check if any item of the given list is in the list | ||||
|         /// </summary> | ||||
|         /// <param name="values">List of items</param> | ||||
|         public bool ContainsAny(AutoList<T, ST> values) | ||||
|         { | ||||
|             foreach (var v in values) | ||||
|                 if (list.Contains((T)v)) | ||||
|                     return true; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         public IEnumerator<T> GetEnumerator() | ||||
|         { | ||||
|             return ((IEnumerable<T>)list).GetEnumerator(); | ||||
|         } | ||||
|  | ||||
|         IEnumerator IEnumerable.GetEnumerator() | ||||
|         { | ||||
|             return ((IEnumerable<T>)list).GetEnumerator(); | ||||
|         } | ||||
|  | ||||
|         public void CopyTo(Array array, int index) | ||||
|         { | ||||
|             (list as ICollection).CopyTo(array, index); | ||||
|         } | ||||
|  | ||||
|         public void CopyTo(T[] array, int arrayIndex) | ||||
|         { | ||||
|             list.CopyTo(array, arrayIndex); | ||||
|         } | ||||
|  | ||||
|         bool ICollection<T>.Remove(T item) | ||||
|         { | ||||
|             return list.Remove(item); | ||||
|             return syncRoot; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// First item in the list | ||||
|     /// </summary> | ||||
|     public T First() | ||||
|     { | ||||
|         return list.First(); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Get an item at a specified index | ||||
|     /// </summary> | ||||
|     public T this[int index] | ||||
|     { | ||||
|         get | ||||
|         { | ||||
|             return list[index]; | ||||
|         } | ||||
|         set | ||||
|         { | ||||
|             var oldValue = list[index]; | ||||
|  | ||||
|             lock (syncRoot) | ||||
|                 list[index] = value; | ||||
|  | ||||
|             OnModified?.Invoke(state, index, oldValue, value); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Add item to the list | ||||
|     /// </summary> | ||||
|     public void Add(T value) | ||||
|     { | ||||
|         lock (syncRoot) | ||||
|             list.Add(value); | ||||
|  | ||||
|         OnAdd?.Invoke(state, value); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Add an array of items to the list | ||||
|     /// </summary> | ||||
|     public void AddRange(T[] values) | ||||
|     { | ||||
|         foreach (var v in values) | ||||
|             Add(v); | ||||
|     } | ||||
|  | ||||
|     private void ItemDestroyed(object sender) | ||||
|     { | ||||
|         Remove((T)sender); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Clear the list | ||||
|     /// </summary> | ||||
|     public void Clear() | ||||
|     { | ||||
|  | ||||
|         lock (syncRoot) | ||||
|             list.Clear(); | ||||
|  | ||||
|         OnCleared?.Invoke(state); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Remove an item from the list | ||||
|     /// <param name="value">Item to remove</param> | ||||
|     /// </summary> | ||||
|     public void Remove(T value) | ||||
|     { | ||||
|         var index = 0; | ||||
|  | ||||
|         lock (syncRoot) | ||||
|         { | ||||
|             index = list.IndexOf(value); | ||||
|  | ||||
|             if (index == -1) | ||||
|                 return; | ||||
|  | ||||
|             list.RemoveAt(index); | ||||
|  | ||||
|  | ||||
|         } | ||||
|  | ||||
|         OnRemoved?.Invoke(state, index, value); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Number of items in the list | ||||
|     /// </summary> | ||||
|     public int Count | ||||
|     { | ||||
|         get { return list.Count; } | ||||
|     } | ||||
|  | ||||
|     public bool IsSynchronized => (list as ICollection).IsSynchronized; | ||||
|  | ||||
|     public bool IsReadOnly => throw new NotImplementedException(); | ||||
|  | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Check if an item exists in the list | ||||
|     /// </summary> | ||||
|     /// <param name="value">Item to check if exists</param> | ||||
|     public bool Contains(T value) | ||||
|     { | ||||
|         return list.Contains(value); | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Check if any item of the given array is in the list | ||||
|     /// </summary> | ||||
|     /// <param name="values">Array of items</param> | ||||
|     public bool ContainsAny(T[] values) | ||||
|     { | ||||
|         foreach (var v in values) | ||||
|             if (list.Contains(v)) | ||||
|                 return true; | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     /// <summary> | ||||
|     /// Check if any item of the given list is in the list | ||||
|     /// </summary> | ||||
|     /// <param name="values">List of items</param> | ||||
|     public bool ContainsAny(AutoList<T, ST> values) | ||||
|     { | ||||
|         foreach (var v in values) | ||||
|             if (list.Contains((T)v)) | ||||
|                 return true; | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public IEnumerator<T> GetEnumerator() | ||||
|     { | ||||
|         return ((IEnumerable<T>)list).GetEnumerator(); | ||||
|     } | ||||
|  | ||||
|     IEnumerator IEnumerable.GetEnumerator() | ||||
|     { | ||||
|         return ((IEnumerable<T>)list).GetEnumerator(); | ||||
|     } | ||||
|  | ||||
|     public void CopyTo(Array array, int index) | ||||
|     { | ||||
|         (list as ICollection).CopyTo(array, index); | ||||
|     } | ||||
|  | ||||
|     public void CopyTo(T[] array, int arrayIndex) | ||||
|     { | ||||
|         list.CopyTo(array, arrayIndex); | ||||
|     } | ||||
|  | ||||
|     bool ICollection<T>.Remove(T item) | ||||
|     { | ||||
|         return list.Remove(item); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user