Skip to content

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sleushunou authored Jul 17, 2024
1 parent ef82b6d commit 1043521
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Softeq.XToolkit.Common.iOS/Extensions/NSStringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,21 +49,40 @@ public static NSMutableAttributedString BuildAttributedString(this string input)
/// </summary>
/// <param name="html">Any HTML string.</param>
/// <param name="encoding">HTML encoding.</param>
/// <param name="logger">logger for error logging.</param>
/// <returns>New instance of <see cref="T:Foundation.NSMutableAttributedString"/>.</returns>
public static NSMutableAttributedString BuildAttributedStringFromHtml(
this string html,
NSStringEncoding encoding = NSStringEncoding.UTF8)
NSStringEncoding encoding = NSStringEncoding.UTF8,
ILogger? logger = null)
{
var importParams = new NSAttributedStringDocumentAttributes
{
DocumentType = NSDocumentType.HTML,
StringEncoding = encoding
};

var error = new NSError();
NSError? error = null;

var attributedString = new NSAttributedString(html, importParams, ref error);
return new NSMutableAttributedString(attributedString);
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)
{
logger?.Error(ex);
throw;
}
finally
{
if (error != null)
{
logger?.Info("Error message: " + error.Description);
}
}
}

/// <summary>
Expand Down

0 comments on commit 1043521

Please sign in to comment.