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
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ T:System.Web.SameSiteMode

T:Microsoft.AspNetCore.SystemWebAdapters.IBrowserCapabilitiesFactory
T:Microsoft.AspNetCore.SystemWebAdapters.IHttpBrowserCapabilityFeature

# We provide implementations of this on .NET Standard 2.0 and .NET 6.0
T:System.Web.IHtmlString

# We implement extra interfaces that end up getting added to the generated stuff
T:System.Web.HtmlString
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Html;

using CoreHtmlString = Microsoft.AspNetCore.Html.HtmlString;

namespace System.Web;

public partial class HtmlString : IHtmlContent
{
[SuppressMessage("Design", "CA1033:Interface methods should be callable by child types", Justification = Constants.ApiFromAspNet)]
void IHtmlContent.WriteTo(TextWriter writer, HtmlEncoder encoder)
{
writer.Write(_htmlString);
}

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator HtmlString?(CoreHtmlString? other)
=> other is null ? null : new(other.Value ?? string.Empty);

[return: NotNullIfNotNull(nameof(other))]
public static implicit operator CoreHtmlString?(HtmlString? other)
=> other is null ? null : new(other._htmlString);
}
#endif
19 changes: 19 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HtmlString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETFRAMEWORK
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HtmlString))]
#else
namespace System.Web;

public partial class HtmlString : IHtmlString
{
private readonly string _htmlString;

public HtmlString(string value) => _htmlString = value;

public string ToHtmlString() => _htmlString;

public override string ToString() => _htmlString;
}
#endif
18 changes: 18 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/IHtmlString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// This is available in-box in .NET Framework and .NET 8+. We type forward to that when possible, otherwise, provide an implementation here for compat purposes.
#if NETSTANDARD || NET6_0

namespace System.Web;

public interface IHtmlString
{
string ToHtmlString();
}

#else

[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.IHtmlString))]

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<Compile Include="Properties/PropertyInfo.cs" />
<Compile Include="Generated/Ref.*.cs" />
<Compile Include="Adapters/SessionState/ISessionState.cs" />
<Compile Include="IHtmlString.cs" />
<Compile Include="HtmlString.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
Expand All @@ -45,6 +47,9 @@
<Compile Include="Adapters/**/*.cs" />
<Compile Include="Generated/TypeForwards.*.cs" />

<Compile Include="IHtmlString.cs" />
<Compile Include="HtmlString.cs" />

<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down