-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSectionedOutput.cs
More file actions
50 lines (42 loc) · 2.18 KB
/
Copy pathSectionedOutput.cs
File metadata and controls
50 lines (42 loc) · 2.18 KB
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
using NeoReports.Core.Sections;
namespace NeoReports.Core.Building;
/// <summary>
/// A configured sectioned output: the factory that produces a single-file, multi-section writer
/// (e.g. an XLSX workbook) plus its options. Section (sheet) definitions are supplied on the builder.
/// </summary>
public sealed class SectionedOutputSpec
{
/// <summary>Creates a sectioned output specification.</summary>
/// <param name="factory">Factory that creates the sectioned writer.</param>
/// <param name="options">Format-specific options; <c>null</c> is treated as empty.</param>
public SectionedOutputSpec(ISectionedWriterFactory factory, IReadOnlyDictionary<string, object?>? options = null)
{
Factory = factory ?? throw new ArgumentNullException(nameof(factory));
Options = options ?? new Dictionary<string, object?>();
}
/// <summary>Factory that creates the sectioned writer.</summary>
public ISectionedWriterFactory Factory { get; }
/// <summary>Format-specific options.</summary>
public IReadOnlyDictionary<string, object?> Options { get; }
}
/// <summary>Collects the sections (e.g. worksheets) of a sectioned output, each with its own view.</summary>
/// <typeparam name="TRow">The report's row type.</typeparam>
public sealed class SectionBuilder<TRow>
{
internal List<SectionDefinition<TRow>> Sections { get; } = [];
/// <summary>Adds a named section with its own filters and/or columns.</summary>
/// <param name="name">Section (sheet) name.</param>
/// <param name="configureView">Configures the section's filters and columns.</param>
public SectionBuilder<TRow> Section(string name, Action<OutputView<TRow>> configureView)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Section name must be provided.", nameof(name));
ArgumentNullException.ThrowIfNull(configureView);
var view = new OutputView<TRow>();
configureView(view);
Sections.Add(new SectionDefinition<TRow>(name, view));
return this;
}
}
/// <summary>One section's name and its view (filters + columns).</summary>
internal sealed record SectionDefinition<TRow>(string Name, OutputView<TRow> View);