Added Replace with ofT and inex

This commit is contained in:
TheXamlGuy
2024-10-04 16:07:21 +01:00
parent 0c091b3a27
commit e1334ccae7
2 changed files with 27 additions and 1 deletions
@@ -524,6 +524,32 @@ public partial class ObservableCollection<TViewModel> :
Activate();
}
public bool Replace<T>(int index,
params object?[] parameters)
where T :
TViewModel
{
if (index <= Count - 1)
{
RemoveItem(index);
}
else
{
index = Count;
}
T? item = Factory.Create<T>(args =>
{
if (args is IInitialization initialization)
{
initialization.Initialize();
}
}, parameters);
Insert(index, item);
return true;
}
public TViewModel Insert<T>(int index = 0,
params object?[] parameters)
where T :
+1 -1
View File
@@ -2,6 +2,6 @@
public record RemoveAt
{
public static RemoveAtEventArgs<TValue> As<TValue>(int index) =>
public static RemoveAtEventArgs<TSender> As<TSender>(int index) =>
new(index);
}