using System; using System.Collections.Generic; using System.Threading; namespace ACE.Entity.Models { public static class PropertiesBookPageDataExtensions { public static int GetPageCount(this IList value, ReaderWriterLockSlim rwLock) { if (value == null) return 0; rwLock.EnterReadLock(); try { return value.Count; } finally { rwLock.ExitReadLock(); } } public static List Clone(this IList value, ReaderWriterLockSlim rwLock) { if (value == null) return null; rwLock.EnterReadLock(); try { return new List(value); } finally { rwLock.ExitReadLock(); } } public static PropertiesBookPageData GetPage(this IList value, int index, ReaderWriterLockSlim rwLock) { if (value == null) return null; rwLock.EnterReadLock(); try { if (value.Count <= index) return null; return value[index]; } finally { rwLock.ExitReadLock(); } } public static void AddPage(this IList value, PropertiesBookPageData page, out int index, ReaderWriterLockSlim rwLock) { rwLock.EnterWriteLock(); try { value.Add(page); index = value.Count - 1; } finally { rwLock.ExitWriteLock(); } } public static bool RemovePage(this IList value, int index, ReaderWriterLockSlim rwLock) { if (value == null) return false; rwLock.EnterWriteLock(); try { if (value.Count <= index) return false; value.RemoveAt(index); return true; } finally { rwLock.ExitWriteLock(); } } } }