-
Notifications
You must be signed in to change notification settings - Fork 67
Add HttpPostedFile*. #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HttpPostedFile*. #260
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||
| } |
| 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(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we making all of the wrapper types public? Why?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| { | ||
| 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; | ||
| } | ||
There was a problem hiding this comment.
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]parameterThere was a problem hiding this comment.
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.