pascalabcnet/SyntaxTree/tree/SyntaxTemplates/SyntaxWithListMethods.txt

148 lines
3.7 KiB
Plaintext
Raw Normal View History

public <#NodeName#> Add(<#ListElementType#> elem, SourceContext sc = null)
{
<#ListName#>.Add(elem);
2017-06-02 03:38:42 +03:00
if (elem != null)
elem.Parent = this;
if (sc != null)
source_context = sc;
return this;
}
public void AddFirst(<#ListElementType#> el)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
<#ListName#>.Insert(0, el);
FillParentsInDirectChilds();
}
public void AddFirst(IEnumerable<<#ListElementType#>> els)
{
2017-06-02 03:20:10 +03:00
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)
{
2017-06-02 03:20:10 +03:00
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)
{
2017-06-02 03:20:10 +03:00
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)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
if (newel == null)
throw new ArgumentNullException(nameof(newel));
2017-02-12 22:01:44 +03:00
<#ListName#>.Insert(FindIndexInList(el) + 1, newel);
2017-06-02 03:20:10 +03:00
newel.Parent = this;
}
public void InsertAfter(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
if (newels == null)
throw new ArgumentNullException(nameof(newels));
2017-02-12 22:01:44 +03:00
<#ListName#>.InsertRange(FindIndexInList(el) + 1, newels);
foreach (var newel in newels)
if (newel != null)
newel.Parent = this;
}
public void InsertBefore(<#ListElementType#> el, <#ListElementType#> newel)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
if (newel == null)
throw new ArgumentNullException(nameof(newel));
2017-02-12 22:01:44 +03:00
<#ListName#>.Insert(FindIndexInList(el), newel);
2017-06-02 03:20:10 +03:00
newel.Parent = this;
}
public void InsertBefore(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
if (newels == null)
throw new ArgumentNullException(nameof(newels));
2017-02-12 22:01:44 +03:00
<#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)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
if (newel == null)
throw new ArgumentNullException(nameof(newel));
<#ListName#>[FindIndexInList(el)] = newel;
2017-06-02 03:20:10 +03:00
newel.Parent = this;
}
public void ReplaceInList(<#ListElementType#> el, IEnumerable<<#ListElementType#>> newels)
{
2017-06-02 03:20:10 +03:00
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()
{
2017-06-02 03:20:10 +03:00
if (<#ListName#>.Count > 0)
return <#ListName#>[<#ListName#>.Count - 1];
throw new InvalidOperationException("Список пуст");
}
2017-06-01 21:54:52 +03:00
public int Count
{
get { return <#ListName#>.Count; }
}
public void Insert(int pos, <#ListElementType#> el)
{
2017-06-02 03:20:10 +03:00
if (el == null)
throw new ArgumentNullException(nameof(el));
2017-06-01 21:54:52 +03:00
<#ListName#>.Insert(pos,el);
if (el != null)
el.Parent = this;
}