Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/MudBlazor.Markdown/MudBlazor.Markdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Markdig" Version="1.1.3" />
<PackageReference Include="MudBlazor" Version="9.2.0" />
<PackageReference Include="MudBlazor" Version="9.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
63 changes: 63 additions & 0 deletions src/MudBlazor.Markdown/Utils/Extensions/MudBlazorEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#if NET10_0_OR_GREATER
using System.Runtime.CompilerServices;
#else
using System.Reflection;
#endif

namespace MudBlazor;

internal static class MudBlazorEx
{
#if NET10_0_OR_GREATER
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "ToStringFast")]
private static extern string MudToStringFast(
[UnsafeAccessorType("MudBlazor.ColorExtensions, MudBlazor")]
object _,
Color color
);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "ToStringFast")]
private static extern string MudToStringFast(
[UnsafeAccessorType("MudBlazor.UnderlineExtensions, MudBlazor")]
object _,
Underline underline
);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "ToStringFast")]
private static extern string MudToStringFast(
[UnsafeAccessorType("MudBlazor.TypoExtensions, MudBlazor")]
object _,
Typo typo
);
#else
private static string MudToStringFast(object _, Color color)
{
var extensions = typeof(Color).Assembly.GetType("MudBlazor.ColorExtensions");
var method = extensions?.GetMethod("ToStringFast", types: [typeof(Color)], bindingAttr: BindingFlags.Public | BindingFlags.Static);
return (string?)method?.Invoke(null, [color]) ?? throw new InvalidOperationException("Unable to find Color from MudBlazor");
}

private static string MudToStringFast(object _, Underline underline)
{
var extensions = typeof(Underline).Assembly.GetType("MudBlazor.UnderlineExtensions");
var method = extensions?.GetMethod("ToStringFast", types: [typeof(Underline)], bindingAttr: BindingFlags.Public | BindingFlags.Static);
return (string?)method?.Invoke(null, [underline]) ?? throw new InvalidOperationException("Unable to find Underline from MudBlazor");
}

private static string MudToStringFast(object _, Typo typo)
{
var extensions = typeof(Typo).Assembly.GetType("MudBlazor.TypoExtensions");
var method = extensions?.GetMethod("ToStringFast", types: [typeof(Typo)], bindingAttr: BindingFlags.Public | BindingFlags.Static);
return (string?)method?.Invoke(null, [typo]) ?? throw new InvalidOperationException("Unable to find Typo from MudBlazor");
}
#endif

public static string ToStringFast(this Color color)
=> MudToStringFast(null!, color);

public static string ToStringFast(this Underline underline)
=> MudToStringFast(null!, underline);

public static string ToStringFast(this Typo typo)
=> MudToStringFast(null!, typo);
}
Loading