From 231fb88a6aeed1390a3fe3cb8f5016eb64c083c8 Mon Sep 17 00:00:00 2001 From: chinaniit Date: Wed, 28 Dec 2022 19:09:49 +0800 Subject: [PATCH 1/5] Add HttpPostedFile*. --- .../HttpFileCollection.cs | 6 ++- .../HttpFileCollectionBase.cs | 22 ++++++++++ .../HttpFileCollectionWrapper.cs | 43 +++++++++++++++++++ .../HttpPostedFileBase.cs | 17 ++++++++ .../HttpPostedFileWrapper.cs | 29 +++++++++++++ .../HttpRequestBase.cs | 2 + .../HttpRequestWrapper.cs | 2 + 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs index eda8a35484..63be3118d7 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollection.cs @@ -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 GetMultiple(string name) => FormFiles.GetFiles(name) is { Count: > 0 } files ? new ReadOnlyPostedFileCollection(files) : Array.Empty(); public HttpPostedFile? this[string name] => Get(name); + public HttpPostedFile? this[int index] => Get(index); + private string[] GetKeys() { if (FormFiles.Count == 0) @@ -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; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs new file mode 100644 index 0000000000..a2fafb0072 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs @@ -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 GetMultiple(string name) => throw new NotImplementedException(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs new file mode 100644 index 0000000000..f3c1902925 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs @@ -0,0 +1,43 @@ +// 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) => new HttpPostedFileWrapper(_collection[name]); + + public override HttpPostedFileBase Get(int index) => new HttpPostedFileWrapper(_collection[index]); + + public override IList GetMultiple(string name) + => _collection.GetMultiple(name) + .Select(x=> (HttpPostedFileBase)new HttpPostedFileWrapper(x)) + .ToList() + .AsReadOnly(); + + public override IEnumerator GetEnumerator() => _collection.GetEnumerator(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs new file mode 100644 index 0000000000..547d8dc482 --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs @@ -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(); + + public virtual string ContentType => throw new NotImplementedException(); + + public virtual int ContentLength => throw new NotImplementedException(); + + public virtual Stream InputStream => throw new NotImplementedException(); +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs new file mode 100644 index 0000000000..b3f89a6c8a --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs @@ -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 +{ + 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; +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs index f6a6ab71bd..4380693a5b 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs @@ -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(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs index 1f0f9208ea..f0b7906fb4 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs @@ -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; From 1a2ee54ab58652b34008a76b6ca513b83978160a Mon Sep 17 00:00:00 2001 From: chinaniit Date: Wed, 28 Dec 2022 19:16:47 +0800 Subject: [PATCH 2/5] Update Typeforwards. --- .../Generated/Ref.Standard.cs | 42 +++++++++++++++++++ .../Generated/TypeForwards.Framework.cs | 4 ++ 2 files changed, 46 insertions(+) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index 2363bc54d9..9573708f28 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -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 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 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 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() { } @@ -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() { } @@ -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");} } @@ -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");} } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs index 92d6700e46..9a1d24c6b6 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs @@ -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))] From 450dd302cfb750e64d514bec16312edad858541c Mon Sep 17 00:00:00 2001 From: chinaniit Date: Wed, 28 Dec 2022 19:31:50 +0800 Subject: [PATCH 3/5] HttpPostedFileBase -> HttpPostedFileBase? --- .../HttpFileCollectionBase.cs | 8 ++++---- .../HttpFileCollectionWrapper.cs | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs index a2fafb0072..01e3176da9 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs @@ -10,13 +10,13 @@ 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[string name] => throw new NotImplementedException(); - public virtual HttpPostedFileBase this[int index] => 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(int index) => throw new NotImplementedException(); - public virtual HttpPostedFileBase Get(string name) => throw new NotImplementedException(); + public virtual HttpPostedFileBase? Get(string name) => throw new NotImplementedException(); public virtual IList GetMultiple(string name) => throw new NotImplementedException(); } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs index f3c1902925..c3fbf6f60e 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs @@ -25,13 +25,15 @@ public HttpFileCollectionWrapper(HttpFileCollection httpFileCollection) public override int Count => _collection.Count; - public override HttpPostedFileBase this[string name] => Get(name); + public override HttpPostedFileBase? this[string name] => Get(name); - public override HttpPostedFileBase this[int index] => Get(index); + public override HttpPostedFileBase? this[int index] => Get(index); - public override HttpPostedFileBase Get(string name) => new HttpPostedFileWrapper(_collection[name]); + public override HttpPostedFileBase? Get(string name) => + _collection[name] is { } file ? new HttpPostedFileWrapper(file) : null; - public override HttpPostedFileBase Get(int index) => new HttpPostedFileWrapper(_collection[index]); + public override HttpPostedFileBase? Get(int index) => + _collection[index] is { } file ? new HttpPostedFileWrapper(file) : null; public override IList GetMultiple(string name) => _collection.GetMultiple(name) From 445680dfa0769bdfba8d437a7a40a62a9341f310 Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Fri, 17 Feb 2023 09:57:58 -0800 Subject: [PATCH 4/5] Add suppression attributes --- .../HttpFileCollectionBase.cs | 4 ++++ .../HttpFileCollectionWrapper.cs | 1 + .../HttpPostedFileBase.cs | 1 + 3 files changed, 6 insertions(+) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs index 01e3176da9..278b6257ba 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionBase.cs @@ -6,8 +6,12 @@ namespace System.Web; +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] +[Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] public abstract class HttpFileCollectionBase : NameObjectCollectionBase { + [Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = Constants.ApiFromAspNet)] public virtual string[] AllKeys => throw new NotImplementedException(); public virtual HttpPostedFileBase? this[string name] => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs index c3fbf6f60e..c3f309e6ce 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs @@ -7,6 +7,7 @@ namespace System.Web; +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] public class HttpFileCollectionWrapper: HttpFileCollectionBase { private readonly HttpFileCollection _collection; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs index 547d8dc482..71e7c74251 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileBase.cs @@ -5,6 +5,7 @@ namespace System.Web; +[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] public abstract class HttpPostedFileBase { public virtual string FileName => throw new NotImplementedException(); From dc3476a3467ebe493ea9186dc2eb4e3207c9bd16 Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Fri, 17 Feb 2023 10:02:30 -0800 Subject: [PATCH 5/5] use throw helper --- .../HttpFileCollectionWrapper.cs | 9 +++------ .../HttpPostedFileWrapper.cs | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs index c3f309e6ce..aba6ff30b6 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpFileCollectionWrapper.cs @@ -8,16 +8,13 @@ namespace System.Web; [Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] -public class HttpFileCollectionWrapper: HttpFileCollectionBase +public class HttpFileCollectionWrapper : HttpFileCollectionBase { private readonly HttpFileCollection _collection; public HttpFileCollectionWrapper(HttpFileCollection httpFileCollection) { - if (httpFileCollection == null) - { - throw new ArgumentNullException(nameof(httpFileCollection)); - } + ArgumentNullException.ThrowIfNull(httpFileCollection); _collection = httpFileCollection; } @@ -38,7 +35,7 @@ public HttpFileCollectionWrapper(HttpFileCollection httpFileCollection) public override IList GetMultiple(string name) => _collection.GetMultiple(name) - .Select(x=> (HttpPostedFileBase)new HttpPostedFileWrapper(x)) + .Select(x => (HttpPostedFileBase)new HttpPostedFileWrapper(x)) .ToList() .AsReadOnly(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs index b3f89a6c8a..787e8a5dcd 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpPostedFileWrapper.cs @@ -11,10 +11,7 @@ public class HttpPostedFileWrapper : HttpPostedFileBase public HttpPostedFileWrapper(HttpPostedFile httpPostedFile) { - if (httpPostedFile == null) - { - throw new ArgumentNullException(nameof(httpPostedFile)); - } + ArgumentNullException.ThrowIfNull(httpPostedFile); _file = httpPostedFile; }