From c980ca62c895158e768748fe83f63d2a61d97c67 Mon Sep 17 00:00:00 2001 From: Steven De Kock Date: Fri, 12 Aug 2022 09:56:06 +0200 Subject: [PATCH] Add implicit casts for HttpContextBase/HttpRequestBase/HttpResponseBase classes to/from ASP.NET Core variants. --- .../HttpRequestBase.cs | 5 +++++ .../HttpResponseBase.cs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs index 4084ff998f..43c6f0e10d 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs @@ -2,9 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Specialized; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Security.Principal; using System.Text; +using Microsoft.AspNetCore.SystemWebAdapters; namespace System.Web { @@ -79,5 +81,8 @@ public virtual string? ContentType public virtual byte[] BinaryRead(int count) => throw new NotImplementedException(); public virtual void Abort() => throw new NotImplementedException(); + + [return: NotNullIfNotNull("request")] + public static implicit operator HttpRequestBase?(HttpRequestCore? request) => request?.GetAdapterBase(); } } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs index 60495ce6a6..1c50eef1c7 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs @@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; +using Microsoft.AspNetCore.SystemWebAdapters; namespace System.Web { @@ -108,5 +109,8 @@ public virtual TextWriter Output public virtual void TransmitFile(string filename) => throw new NotImplementedException(); public virtual void TransmitFile(string filename, long offset, long length) => throw new NotImplementedException(); + + [return: NotNullIfNotNull("response")] + public static implicit operator HttpResponseBase?(HttpResponseCore? response) => response?.GetAdapterBase(); } }