57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using Demo.Common.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Demo.Common.Extensions
|
|
{
|
|
public static class ObservableCollectionExtension
|
|
{
|
|
public static void InitUserList<T>(this ObservableCollection<T> list, int count) where T : User
|
|
{
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
list.Add((T)User.GetInit());
|
|
}
|
|
}
|
|
|
|
public static int AddUser<T>(this ObservableCollection<T> list, T user) where T : User
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (list[i].Id == 0)
|
|
{
|
|
list[i] = user;
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static int ClearUserById<T>(this ObservableCollection<T> list, long Id) where T : User
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
if (list[i].Id == Id)
|
|
{
|
|
list[i] = (T)User.GetInit();
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public static void ClearAllUser<T>(this ObservableCollection<T> list) where T : User
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
list[i] = (T)User.GetInit();
|
|
}
|
|
}
|
|
}
|
|
}
|