-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathReportFormatParser.cs
More file actions
50 lines (43 loc) · 1.85 KB
/
Copy pathReportFormatParser.cs
File metadata and controls
50 lines (43 loc) · 1.85 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
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Xml;
using System.Linq;
namespace Coverlet.Collector.Utilities
{
internal class ReportFormatParser
{
internal string[] ParseReportFormats(XmlElement configurationElement)
{
string[] formats = Array.Empty<string>();
if (configurationElement != null)
{
XmlElement reportFormatElement = configurationElement[CoverletConstants.ReportFormatElementName];
formats = SplitElement(reportFormatElement);
}
return formats is null || formats.Length == 0 ? new[] { CoverletConstants.DefaultReportFormat } : formats;
}
private static string[] SplitElement(XmlElement element)
{
return element?.InnerText?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(value => !string.IsNullOrWhiteSpace(value)).Select(value => value.Trim()).ToArray();
}
internal bool ParseUseSourceLink(XmlElement configurationElement)
{
XmlElement useSourceLinkElement = configurationElement[CoverletConstants.UseSourceLinkElementName];
bool.TryParse(useSourceLinkElement?.InnerText, out bool useSourceLink);
return useSourceLink;
}
internal bool ParseDeterministicReport(XmlElement configurationElement)
{
XmlElement deterministicReportElement = configurationElement[CoverletConstants.DeterministicReport];
bool.TryParse(deterministicReportElement?.InnerText, out bool deterministicReport);
return deterministicReport;
}
internal bool ParseReportMerging(XmlElement configurationElement)
{
XmlElement mergeWithElement = configurationElement[CoverletConstants.ReportMerging];
bool.TryParse(mergeWithElement?.InnerText, out bool mergeWith);
return mergeWith;
}
}
}