148 lines
3.7 KiB
Plaintext
148 lines
3.7 KiB
Plaintext
public <#NodeName#> Add(<#ListElementType#> elem, SourceContext sc = null)
|
||
{
|
||
<#ListName#>.Add(elem);
|
||
if (elem != null)
|
||
elem.Parent = this;
|
||
if (sc != null)
|
||
source_context = sc;
|
||
return this;
|
||
}
|
||
|
||
public void AddFirst(<#ListElementType#> el)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
<#ListName#>.Insert(0, el);
|
||
FillParentsInDirectChilds();
|
||
}
|
||
|
||
public void AddFirst(IEnumerable<<#ListElementType#>> els)
|
||
{
|
||
if (els == null)
|
||
throw new ArgumentNullException(nameof(els));
|
||
<#ListName#>.InsertRange(0, els);
|
||
foreach (var el in els)
|
||
if (el != null)
|
||
el.Parent = this;
|
||
}
|
||
|
||
public void AddMany(params <#ListElementType#>[] els)
|
||
{
|
||
if (els == null)
|
||
throw new ArgumentNullException(nameof(els));
|
||
<#ListName#>.AddRange(els);
|
||
foreach (var el in els)
|
||
if (el != null)
|
||
el.Parent = this;
|
||
}
|
||
|
||
private int FindIndexInList(<#ListElementType#> el)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
var ind = <#ListName#>.FindIndex(x => x == el);
|
||
if (ind == -1)
|
||
throw new Exception(string.Format("У списка {0} не найден элемент {1} среди дочерних\n", this, el));
|
||
return ind;
|
||
}
|
||
|
||
public void InsertAfter(<#ListElementType#> el, <#ListElementType#> newel)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newel == null)
|
||
throw new ArgumentNullException(nameof(newel));
|
||
<#ListName#>.Insert(FindIndexInList(el) + 1, newel);
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newels == null)
|
||
throw new ArgumentNullException(nameof(newels));
|
||
<#ListName#>.InsertRange(FindIndexInList(el) + 1, newels);
|
||
foreach (var newel in newels)
|
||
if (newel != null)
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public void InsertBefore(<#ListElementType#> el, <#ListElementType#> newel)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newel == null)
|
||
throw new ArgumentNullException(nameof(newel));
|
||
<#ListName#>.Insert(FindIndexInList(el), newel);
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public void InsertBefore(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newels == null)
|
||
throw new ArgumentNullException(nameof(newels));
|
||
<#ListName#>.InsertRange(FindIndexInList(el), newels);
|
||
foreach (var newel in newels)
|
||
if (newel != null)
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public bool Remove(<#ListElementType#> el)
|
||
{
|
||
return <#ListName#>.Remove(el);
|
||
}
|
||
|
||
public void ReplaceInList(<#ListElementType#> el, <#ListElementType#> newel)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newel == null)
|
||
throw new ArgumentNullException(nameof(newel));
|
||
<#ListName#>[FindIndexInList(el)] = newel;
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public void ReplaceInList(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
if (newels == null)
|
||
throw new ArgumentNullException(nameof(newels));
|
||
var ind = FindIndexInList(el);
|
||
<#ListName#>.RemoveAt(ind);
|
||
<#ListName#>.InsertRange(ind, newels);
|
||
foreach (var newel in newels)
|
||
if (newel != null)
|
||
newel.Parent = this;
|
||
}
|
||
|
||
public int RemoveAll(Predicate<<#ListElementType#>> match)
|
||
{
|
||
return <#ListName#>.RemoveAll(match);
|
||
}
|
||
|
||
public <#ListElementType#> Last()
|
||
{
|
||
if (<#ListName#>.Count > 0)
|
||
return <#ListName#>[<#ListName#>.Count - 1];
|
||
throw new InvalidOperationException("Список пуст");
|
||
}
|
||
|
||
public int Count
|
||
{
|
||
get { return <#ListName#>.Count; }
|
||
}
|
||
|
||
public void Insert(int pos, <#ListElementType#> el)
|
||
{
|
||
if (el == null)
|
||
throw new ArgumentNullException(nameof(el));
|
||
<#ListName#>.Insert(pos,el);
|
||
if (el != null)
|
||
el.Parent = this;
|
||
}
|
||
|