pascalabcnet/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt
2017-06-01 23:49:15 +03:00

115 lines
2.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
{
<#ListName#>.Insert(0, el);
FillParentsInDirectChilds();
}
public void AddFirst(IEnumerable<<#ListElementType#>> els)
{
<#ListName#>.InsertRange(0, els);
foreach (var el in els)
if (el != null)
el.Parent = this;
}
public void AddMany(params <#ListElementType#>[] els)
{
<#ListName#>.AddRange(els);
foreach (var el in els)
if (el != null)
el.Parent = this;
}
private int FindIndexInList(<#ListElementType#> 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)
{
<#ListName#>.Insert(FindIndexInList(el) + 1, newel);
if (newel != null)
newel.Parent = this;
}
public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> 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)
{
<#ListName#>.Insert(FindIndexInList(el), newel);
if (newel != null)
newel.Parent = this;
}
public void InsertBefore(<#ListElementType#> el, IEnumerable<<#ListElementType#>> 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)
{
<#ListName#>[FindIndexInList(el)] = newel;
if (newel != null)
newel.Parent = this;
}
public void ReplaceInList(<#ListElementType#> el, IEnumerable<<#ListElementType#>> 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()
{
return <#ListName#>[<#ListName#>.Count - 1];
}
public int Count
{
get { return <#ListName#>.Count; }
}
public void Insert(int pos, <#ListElementType#> el)
{
<#ListName#>.Insert(pos,el);
if (el != null)
el.Parent = this;
}