Use generated Regex attribute to generate the expression implementation at compile time.
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace lottery_co_uk_scraper.NationalLottery
|
namespace lottery_co_uk_scraper.NationalLottery
|
||||||
{
|
{
|
||||||
internal class DrawWinnerInformation
|
internal partial class DrawWinnerInformation
|
||||||
{
|
{
|
||||||
public static void ProcessTableSection(HtmlNode table, string sectionTitle, LottoResult lottoResult)
|
public static void ProcessTableSection(HtmlNode table, string sectionTitle, LottoResult lottoResult)
|
||||||
{
|
{
|
||||||
@@ -419,7 +419,7 @@ namespace lottery_co_uk_scraper.NationalLottery
|
|||||||
|
|
||||||
var textNodes = htmlDoc.DocumentNode.DescendantsAndSelf().Where(n => n.NodeType == HtmlNodeType.Text);
|
var textNodes = htmlDoc.DocumentNode.DescendantsAndSelf().Where(n => n.NodeType == HtmlNodeType.Text);
|
||||||
|
|
||||||
var numericValues = textNodes.SelectMany(n => Regex.Matches(n.InnerHtml, @"(\d+)").Cast<Match>())
|
var numericValues = textNodes.SelectMany(n => MyRegex().Matches(n.InnerHtml).Cast<Match>())
|
||||||
.Select(match => int.Parse(match.Groups[1].Value))
|
.Select(match => int.Parse(match.Groups[1].Value))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -449,7 +449,6 @@ namespace lottery_co_uk_scraper.NationalLottery
|
|||||||
|
|
||||||
string columnTitle = prizePerWinnerNode.Attributes["data-title"].Value;
|
string columnTitle = prizePerWinnerNode.Attributes["data-title"].Value;
|
||||||
|
|
||||||
// Now you can use regularPrizePerWinner and rolldownPrizePerWinner as needed
|
|
||||||
Console.WriteLine($"Prize per winner ({sectionTitle}): {regularPrizePerWinner}");
|
Console.WriteLine($"Prize per winner ({sectionTitle}): {regularPrizePerWinner}");
|
||||||
Console.WriteLine($"Rolldown Prize per winner ({sectionTitle}): {rolldownPrizePerWinner}");
|
Console.WriteLine($"Rolldown Prize per winner ({sectionTitle}): {rolldownPrizePerWinner}");
|
||||||
|
|
||||||
@@ -531,5 +530,8 @@ namespace lottery_co_uk_scraper.NationalLottery
|
|||||||
{
|
{
|
||||||
AssignValueToModelProperty(sectionTitle, columnTitle, LotteryTableRow.Total, winnersNode, lottoResult);
|
AssignValueToModelProperty(sectionTitle, columnTitle, LotteryTableRow.Total, winnersNode, lottoResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"(\d+)")]
|
||||||
|
private static partial Regex MyRegex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user