From d105610d91c490afd1c17a203756c82b0321c3b7 Mon Sep 17 00:00:00 2001 From: "s.leushunou" Date: Wed, 17 Jul 2024 15:01:59 +0200 Subject: [PATCH 1/3] add logs --- .../Extensions/NSStringExtensions.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs index 975a36a16..0b83b41e2 100644 --- a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs +++ b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Foundation; using Softeq.XToolkit.Common.Extensions; +using Softeq.XToolkit.Common.Logger; using UIKit; namespace Softeq.XToolkit.Common.iOS.Extensions @@ -48,10 +49,12 @@ public static NSMutableAttributedString BuildAttributedString(this string input) /// /// Any HTML string. /// HTML encoding. + /// logger for error logging. /// New instance of . public static NSMutableAttributedString BuildAttributedStringFromHtml( this string html, - NSStringEncoding encoding = NSStringEncoding.UTF8) + NSStringEncoding encoding = NSStringEncoding.UTF8, + ILogger? logger = null) { var importParams = new NSAttributedStringDocumentAttributes { @@ -59,10 +62,19 @@ public static NSMutableAttributedString BuildAttributedStringFromHtml( StringEncoding = encoding }; - var error = new NSError(); + NSError error = new NSError(); - var attributedString = new NSAttributedString(html, importParams, ref error); - return new NSMutableAttributedString(attributedString); + try + { + var attributedString = new NSAttributedString(html, importParams, ref error); + return new NSMutableAttributedString(attributedString); + } + catch (Exception ex) + { + logger?.Error(ex); + logger?.Info("Error message: " + error.Description); + throw; + } } /// From 2e412f5732807f70d0e4b6152db66bc27b3c2fad Mon Sep 17 00:00:00 2001 From: "s.leushunou" Date: Wed, 17 Jul 2024 15:15:20 +0200 Subject: [PATCH 2/3] fix pr --- .../Extensions/NSStringExtensions.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs index 0b83b41e2..99424bfbb 100644 --- a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs +++ b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs @@ -62,7 +62,7 @@ public static NSMutableAttributedString BuildAttributedStringFromHtml( StringEncoding = encoding }; - NSError error = new NSError(); + var error = new NSError(); try { @@ -72,9 +72,15 @@ public static NSMutableAttributedString BuildAttributedStringFromHtml( catch (Exception ex) { logger?.Error(ex); - logger?.Info("Error message: " + error.Description); throw; } + finally + { + if (error != null) + { + logger?.Info("Error message: " + error.Description); + } + } } /// From 64f984d15f6daf747806b980e664466c92564534 Mon Sep 17 00:00:00 2001 From: "s.leushunou" Date: Wed, 17 Jul 2024 15:23:03 +0200 Subject: [PATCH 3/3] fix pr --- Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs index 99424bfbb..3811527ec 100644 --- a/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs +++ b/Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs @@ -62,11 +62,13 @@ public static NSMutableAttributedString BuildAttributedStringFromHtml( StringEncoding = encoding }; - var error = new NSError(); + NSError? error = null; try { +#pragma warning disable CS8601 // Possible null reference assignment. var attributedString = new NSAttributedString(html, importParams, ref error); +#pragma warning restore CS8601 // Possible null reference assignment. return new NSMutableAttributedString(attributedString); } catch (Exception ex)