Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -135,13 +135,37 @@ public sealed partial class HttpFileCollection : System.Collections.Specialized.
internal HttpFileCollection() { }
public string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public System.Web.HttpPostedFile this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public System.Web.HttpPostedFile this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
[System.ObsoleteAttribute("Retrieving Keys is not supported on .NET 6+. Please use the enumerator instead.")]
public override System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public System.Web.HttpPostedFile Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public System.Web.HttpPostedFile Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public System.Collections.Generic.IList<System.Web.HttpPostedFile> GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public abstract partial class HttpFileCollectionBase : System.Collections.Specialized.NameObjectCollectionBase
{
protected HttpFileCollectionBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpPostedFileBase this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpPostedFileBase this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpPostedFileBase Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Web.HttpPostedFileBase Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual System.Collections.Generic.IList<System.Web.HttpPostedFileBase> GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public partial class HttpFileCollectionWrapper : System.Web.HttpFileCollectionBase
{
public HttpFileCollectionWrapper(System.Web.HttpFileCollection httpFileCollection) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpPostedFileBase this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpPostedFileBase this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpPostedFileBase Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override System.Web.HttpPostedFileBase Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override System.Collections.Generic.IList<System.Web.HttpPostedFileBase> GetMultiple(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public sealed partial class HttpPostedFile
{
internal HttpPostedFile() { }
Expand All @@ -150,6 +174,22 @@ internal HttpPostedFile() { }
public string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
}
public abstract partial class HttpPostedFileBase
{
protected HttpPostedFileBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public virtual int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
}
public partial class HttpPostedFileWrapper : System.Web.HttpPostedFileBase
{
public HttpPostedFileWrapper(System.Web.HttpPostedFile httpPostedFile) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public override int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override string FileName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
}
public partial class HttpRequest
{
internal HttpRequest() { }
Expand Down Expand Up @@ -202,6 +242,7 @@ public abstract partial class HttpRequestBase
public virtual int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Web.HttpFileCollectionBase Files { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual string HttpMethod { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public virtual System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
Expand Down Expand Up @@ -239,6 +280,7 @@ public partial class HttpRequestWrapper : System.Web.HttpRequestBase
public override int ContentLength { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override string ContentType { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpCookieCollection Cookies { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Web.HttpFileCollectionBase Files { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.Collections.Specialized.NameValueCollection Headers { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override string HttpMethod { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public override System.IO.Stream InputStream { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpCookieCollection))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpException))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollection))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollectionBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpFileCollectionWrapper))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFile))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFileBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpPostedFileWrapper))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequest))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequestBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpRequestWrapper))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public override IEnumerator GetEnumerator()

public HttpPostedFile? Get(string name) => FormFiles.GetFile(name) is { } file ? new(file) : null;

public HttpPostedFile? Get(int index) => FormFiles[index] is { } file ? new(file) : null;

public IList<HttpPostedFile> GetMultiple(string name) => FormFiles.GetFiles(name) is { Count: > 0 } files ? new ReadOnlyPostedFileCollection(files) : Array.Empty<HttpPostedFile>();

public HttpPostedFile? this[string name] => Get(name);

public HttpPostedFile? this[int index] => Get(index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tratcher I think this is the first of the namevaluecollection types we can actually fully conform - I hadn't realized IFormFileCollection had a this[int index] parameter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, yeah, it's a full IReadOnlyList.


private string[] GetKeys()
{
if (FormFiles.Count == 0)
Expand Down Expand Up @@ -86,7 +90,7 @@ public HttpPostedFile this[int index]
set => throw new NotSupportedException(Message);
}

private static HttpPostedFile Create(IFormFile file) => new(file);
private static HttpPostedFile Create(IFormFile file) => new HttpPostedFile(file);

public int Count => _other.Count;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Collections.Specialized;

namespace System.Web;

public abstract class HttpFileCollectionBase : NameObjectCollectionBase
{
public virtual string[] AllKeys => throw new NotImplementedException();

public virtual HttpPostedFileBase? this[string name] => throw new NotImplementedException();

public virtual HttpPostedFileBase? this[int index] => throw new NotImplementedException();

public virtual HttpPostedFileBase? Get(int index) => throw new NotImplementedException();

public virtual HttpPostedFileBase? Get(string name) => throw new NotImplementedException();

public virtual IList<HttpPostedFileBase> GetMultiple(string name) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace System.Web;

public class HttpFileCollectionWrapper: HttpFileCollectionBase
{
private readonly HttpFileCollection _collection;

public HttpFileCollectionWrapper(HttpFileCollection httpFileCollection)
{
if (httpFileCollection == null)
{
throw new ArgumentNullException(nameof(httpFileCollection));
}

_collection = httpFileCollection;
}

public override string[] AllKeys => _collection.AllKeys;

public override int Count => _collection.Count;

public override HttpPostedFileBase? this[string name] => Get(name);

public override HttpPostedFileBase? this[int index] => Get(index);

public override HttpPostedFileBase? Get(string name) =>
_collection[name] is { } file ? new HttpPostedFileWrapper(file) : null;

public override HttpPostedFileBase? Get(int index) =>
_collection[index] is { } file ? new HttpPostedFileWrapper(file) : null;

public override IList<HttpPostedFileBase> GetMultiple(string name)
=> _collection.GetMultiple(name)
.Select(x=> (HttpPostedFileBase)new HttpPostedFileWrapper(x))
.ToList()
.AsReadOnly();

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

using System.IO;

namespace System.Web;

public abstract class HttpPostedFileBase
{
public virtual string FileName => throw new NotImplementedException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnLwith for these kind of warnings/errors, suppress with an attribute, and use the justification of Constants.ApiFromAspNet


public virtual string ContentType => throw new NotImplementedException();

public virtual int ContentLength => throw new NotImplementedException();

public virtual Stream InputStream => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;

namespace System.Web;

public class HttpPostedFileWrapper : HttpPostedFileBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we making all of the wrapper types public? Why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public API from .NET Framework: https://learn.microsoft.com/en-us/dotnet/api/system.web.httppostedfilewrapper?view=netframework-4.8.1

It's a convention used for a number of types. Most common is HttpContext which has no virtual methods. HttpContextBase was an abstraction for it. HttpContextWrapper wrapped HttpContext to HttpContextBase.

{
private readonly HttpPostedFile _file;

public HttpPostedFileWrapper(HttpPostedFile httpPostedFile)
{
if (httpPostedFile == null)
{
throw new ArgumentNullException(nameof(httpPostedFile));
}

_file = httpPostedFile;
}

public override int ContentLength => _file.ContentLength;

public override string ContentType => _file.ContentType;

public override string FileName => _file.FileName;

public override Stream InputStream => _file.InputStream;
}
2 changes: 2 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public abstract class HttpRequestBase

public virtual HttpCookieCollection Cookies => throw new NotImplementedException();

public virtual HttpFileCollectionBase Files => throw new NotImplementedException();

public virtual string? this[string key] => throw new NotImplementedException();

public virtual NameValueCollection Params => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public override string? ContentType

public override NameValueCollection Headers => _request.Headers;

public override HttpFileCollectionBase Files => new HttpFileCollectionWrapper(_request.Files);

public override string HttpMethod => _request.HttpMethod;

public override Stream InputStream => _request.InputStream;
Expand Down