Skip to content

Commit db93e6a

Browse files
committed
Add implicit casts for HttpContextBase/HttpRequestBase/HttpResponseBase classes to/from ASP.NET Core variants.
1 parent efbe56e commit db93e6a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections.Specialized;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.IO;
67
using System.Security.Principal;
78
using System.Text;
9+
using Microsoft.AspNetCore.SystemWebAdapters;
810

911
namespace System.Web
1012
{
@@ -79,5 +81,8 @@ public virtual string? ContentType
7981
public virtual byte[] BinaryRead(int count) => throw new NotImplementedException();
8082

8183
public virtual void Abort() => throw new NotImplementedException();
84+
85+
[return: NotNullIfNotNull("request")]
86+
public static implicit operator HttpRequestBase?(HttpRequestCore? request) => request?.GetAdapterBase();
8287
}
8388
}

src/Microsoft.AspNetCore.SystemWebAdapters/HttpResponseBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.CodeAnalysis;
66
using System.IO;
77
using System.Text;
8+
using Microsoft.AspNetCore.SystemWebAdapters;
89

910
namespace System.Web
1011
{
@@ -108,5 +109,8 @@ public virtual TextWriter Output
108109
public virtual void TransmitFile(string filename) => throw new NotImplementedException();
109110

110111
public virtual void TransmitFile(string filename, long offset, long length) => throw new NotImplementedException();
112+
113+
[return: NotNullIfNotNull("response")]
114+
public static implicit operator HttpResponseBase?(HttpResponseCore? response) => response?.GetAdapterBase();
111115
}
112116
}

0 commit comments

Comments
 (0)