From bd02d90829ad6514b2cab23ee218dea0da50c362 Mon Sep 17 00:00:00 2001 From: Felipe Baltazar Date: Sat, 2 Nov 2024 10:36:57 -0300 Subject: [PATCH] Change regex to compile time generation --- Maui.ServerDrivenUI/Models/ServerUIElement.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Maui.ServerDrivenUI/Models/ServerUIElement.cs b/Maui.ServerDrivenUI/Models/ServerUIElement.cs index c03dbb5..9fdf1c6 100644 --- a/Maui.ServerDrivenUI/Models/ServerUIElement.cs +++ b/Maui.ServerDrivenUI/Models/ServerUIElement.cs @@ -8,7 +8,7 @@ namespace Maui.ServerDrivenUI; /// /// Represents a MAUI visual element /// -public class ServerUIElement +public partial class ServerUIElement { #region Properties @@ -114,19 +114,19 @@ public string ToXaml(IList? customNamespaces = null) } var xaml = XamlConverterService.ConvertToXml(this); - return DoRemovespace($"\n" + - $"{xaml}"); + return DoRemovespace(xaml); } #endregion - private static string DoRemovespace(string strFile) + private string DoRemovespace(string str) { - var str = System.IO.File.ReadAllText(strFile); str = str.Replace("\n", ""); str = str.Replace("\r", ""); - var regex = new Regex(@">\s*<"); - return regex.Replace(str, "><"); + return CompactXmlRegex().Replace(str, "><"); } + + [GeneratedRegex(@">\s*<")] + private partial Regex CompactXmlRegex(); }