/
BlockPresenter.cs
76 lines (68 loc) · 2.22 KB
/
BlockPresenter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using DevZest.Data.Presenters.Primitives;
using DevZest.Data.Views;
using System;
using System.Collections;
using System.Collections.Generic;
namespace DevZest.Data.Presenters
{
/// <summary>
/// Contains block level presentation logic which can be consumed by view elements.
/// </summary>
public sealed class BlockPresenter : ElementPresenter, IReadOnlyList<RowPresenter>
{
internal BlockPresenter(Template template)
{
_template = template;
}
private readonly Template _template;
/// <inheritdoc/>
public sealed override Template Template
{
get { return _template; }
}
internal BlockView BlockView { get; set; }
/// <summary>
/// Gets the ordinal of the block.
/// </summary>
public int Ordinal
{
get { return BlockView == null ? -1 : BlockView.Ordinal; }
}
/// <summary>
/// Gets <see cref="RowPresenter"/> at specified index.
/// </summary>
/// <param name="index">The specified index.</param>
/// <returns>The result <see cref="RowPresenter"/>.</returns>
public RowPresenter this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException(nameof(index));
return BlockView[index];
}
}
/// <summary>
/// Gets the count of contained rows.
/// </summary>
public int Count
{
get { return BlockView == null ? 0 : BlockView.Count; }
}
/// <summary>
/// Returns an enumerator that lists all of the <see cref="RowPresenter"/> in this block.
/// </summary>
/// <returns>An enumerator that lists all of the <see cref="RowPresenter"/> in this block.</returns>
public IEnumerator<RowPresenter> GetEnumerator()
{
if (BlockView != null)
return BlockView.GetEnumerator();
else
return EmptyEnumerator<RowPresenter>.Singleton;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}