Added Replace with ofT and inex
This commit is contained in:
@@ -524,6 +524,32 @@ public partial class ObservableCollection<TViewModel> :
|
|||||||
Activate();
|
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,
|
public TViewModel Insert<T>(int index = 0,
|
||||||
params object?[] parameters)
|
params object?[] parameters)
|
||||||
where T :
|
where T :
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
public record RemoveAt
|
public record RemoveAt
|
||||||
{
|
{
|
||||||
public static RemoveAtEventArgs<TValue> As<TValue>(int index) =>
|
public static RemoveAtEventArgs<TSender> As<TSender>(int index) =>
|
||||||
new(index);
|
new(index);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user