2023-07-24 18:37:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2023-07-22 00:20:46 +00:00
|
|
|
|
using System.Text.Encodings.Web;
|
|
|
|
|
using Microsoft.AspNetCore.Html;
|
|
|
|
|
|
|
|
|
|
namespace Cauldron.Macos;
|
|
|
|
|
|
|
|
|
|
public static class Extensions
|
|
|
|
|
{
|
|
|
|
|
public static string RenderAsString(this IHtmlContent htmlContent)
|
|
|
|
|
{
|
|
|
|
|
using (var writer = new StringWriter())
|
|
|
|
|
{
|
|
|
|
|
htmlContent.WriteTo(writer, HtmlEncoder.Default);
|
|
|
|
|
return writer.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-24 18:37:09 +00:00
|
|
|
|
|
|
|
|
|
public static string GetCSharpName(this Type type)
|
|
|
|
|
{
|
|
|
|
|
string name = type.Name;
|
|
|
|
|
|
|
|
|
|
if (!type.IsGenericType)
|
|
|
|
|
return name;
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
|
|
|
|
|
// Get just the name without the generic parameters
|
|
|
|
|
sb.Append(name[..name.IndexOf('`')]);
|
|
|
|
|
|
|
|
|
|
// Add the generic parameters surrounded by < and >
|
|
|
|
|
sb.Append('<');
|
|
|
|
|
sb.Append(type.GetGenericArguments()
|
|
|
|
|
.Select(t => t.GetCSharpName())
|
|
|
|
|
.Join(", "));
|
|
|
|
|
sb.Append('>');
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string Join(this IEnumerable<string> strings, string separator)
|
|
|
|
|
{
|
|
|
|
|
return string.Join(separator, strings);
|
|
|
|
|
}
|
2023-07-22 00:20:46 +00:00
|
|
|
|
}
|