pascalabcnet/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt
2017-02-12 22:01:44 +03:00

78 lines
1.8 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 (sc != null)
source_context = sc;
return this;
}
public void AddFirst(<#ListElementType#> el)
{
<#ListName#>.Insert(0, el);
}
public void AddFirst(IEnumerable<<#ListElementType#>> els)
{
<#ListName#>.InsertRange(0, els);
}
public void AddMany(params <#ListElementType#>[] els)
{
<#ListName#>.AddRange(els);
}
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);
}
public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
<#ListName#>.InsertRange(FindIndexInList(el) + 1, newels);
}
public void InsertBefore(<#ListElementType#> el, <#ListElementType#> newel)
{
<#ListName#>.Insert(FindIndexInList(el), newel);
}
public void InsertBefore(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
<#ListName#>.InsertRange(FindIndexInList(el), newels);
}
public bool Remove(<#ListElementType#> el)
{
return <#ListName#>.Remove(el);
}
public void ReplaceInList(<#ListElementType#> el, <#ListElementType#> newel)
{
<#ListName#>[FindIndexInList(el)] = newel;
}
public void ReplaceInList(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
var ind = FindIndexInList(el);
<#ListName#>.RemoveAt(ind);
<#ListName#>.InsertRange(ind, newels);
}
public int RemoveAll(Predicate<<#ListElementType#>> match)
{
return <#ListName#>.RemoveAll(match);
}
public <#ListElementType#> Last()
{
return <#ListName#>[<#ListName#>.Count - 1];
}