Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logs #556

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 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,32 @@ 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 = new NSError();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed to replace var?


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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that there will be no exception but error is not empty?
And is it possible that error == null here?

throw;
}
}

/// <summary>
Expand Down
Loading