2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2022-10-16 22:16:00 +03:00
parent 8e17a5b677
commit 6537913b11
14 changed files with 516 additions and 1 deletions

103
Esiur/Data/VarList.cs Normal file
View File

@ -0,0 +1,103 @@
using Esiur.Core;
using Esiur.Resource;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace Esiur.Data
{
public class VarList<T> : IEnumerable<T>, ICollection, ICollection<T>
{
string propertyName;
IResource resource;
List<T> list = new List<T>();
public VarList(IResource resource, [CallerMemberName] string propertyName = "")
{
this.resource = resource;
this.propertyName = propertyName;
}
public int Count => list.Count;
public bool IsReadOnly => false;
public bool IsSynchronized => true;
public object SyncRoot { get; } = new object();
public void Add(T item)
{
list.Add(item);
resource?.Instance?.Modified(propertyName);
}
public void Clear()
{
list.Clear();
resource?.Instance?.Modified(propertyName);
}
public bool Contains(T item)
{
return list.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
lock (SyncRoot)
list.CopyTo(array, arrayIndex);
}
public void CopyTo(Array array, int index)
{
lock (SyncRoot)
(list as ICollection).CopyTo(array, index);
}
public IEnumerator<T> GetEnumerator()
{
return list.GetEnumerator();
}
public bool Remove(T item)
{
if ( list.Remove(item))
{
resource?.Instance?.Modified(propertyName);
return true;
}
return false;
}
IEnumerator IEnumerable.GetEnumerator()
{
return list.GetEnumerator();
}
public T this[int index]
{
get
{
return list[index];
}
set
{
//var oldValue = list[index];
lock (SyncRoot)
list[index] = value;
resource?.Instance?.Modified(propertyName);
}
}
}
}