-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f74672
commit 06bda2c
Showing
10 changed files
with
220 additions
and
131 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/SystemWebAdapters/src/Internal/FormCollectionReadOnlyDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Diagnostics.CodeAnalysis; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace System.Web.Internal; | ||
|
||
internal class FormCollectionReadOnlyDictionary : IReadOnlyDictionary<string, StringValues> | ||
{ | ||
private readonly IFormCollection _form; | ||
|
||
public FormCollectionReadOnlyDictionary(IFormCollection form) | ||
{ | ||
_form = form; | ||
} | ||
|
||
public StringValues this[string key] => _form[key]; | ||
|
||
public IEnumerable<string> Keys => _form.Keys; | ||
|
||
public IEnumerable<StringValues> Values | ||
{ | ||
get | ||
{ | ||
foreach (var item in _form) | ||
{ | ||
yield return item.Value; | ||
} | ||
} | ||
} | ||
|
||
public int Count => _form.Count; | ||
|
||
public bool ContainsKey(string key) => _form.ContainsKey(key); | ||
|
||
public IEnumerator<KeyValuePair<string, StringValues>> GetEnumerator() => _form.GetEnumerator(); | ||
|
||
public bool TryGetValue(string key, [MaybeNullWhen(false)] out StringValues value) => _form.TryGetValue(key, out value); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/SystemWebAdapters/src/Internal/QueryCollectionReadOnlyDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Diagnostics.CodeAnalysis; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace System.Web.Internal; | ||
|
||
internal class QueryCollectionReadOnlyDictionary : IReadOnlyDictionary<string, StringValues> | ||
{ | ||
private readonly IQueryCollection _query; | ||
|
||
public QueryCollectionReadOnlyDictionary(IQueryCollection query) | ||
{ | ||
_query = query; | ||
} | ||
|
||
public StringValues this[string key] => _query[key]; | ||
|
||
public IEnumerable<string> Keys => _query.Keys; | ||
|
||
public IEnumerable<StringValues> Values | ||
{ | ||
get | ||
{ | ||
foreach (var item in _query) | ||
{ | ||
yield return item.Value; | ||
} | ||
} | ||
} | ||
|
||
public int Count => _query.Count; | ||
|
||
public bool ContainsKey(string key) => _query.ContainsKey(key); | ||
|
||
public IEnumerator<KeyValuePair<string, StringValues>> GetEnumerator() => _query.GetEnumerator(); | ||
|
||
public bool TryGetValue(string key, [MaybeNullWhen(false)] out StringValues value) => _query.TryGetValue(key, out value); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/SystemWebAdapters/src/Internal/StringValuesNameValueCollection.cs
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/SystemWebAdapters/src/Internal/StringValuesReadOnlyDictionaryNameValueCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using Microsoft.Extensions.Primitives; | ||
|
||
namespace System.Web.Internal | ||
{ | ||
internal class StringValuesReadOnlyDictionaryNameValueCollection : WrappingNameValueCollection | ||
{ | ||
private readonly IReadOnlyDictionary<string, StringValues> _values; | ||
|
||
public static NameValueCollection Empty { get; } = new StringValuesReadOnlyDictionaryNameValueCollection(); | ||
|
||
public StringValuesReadOnlyDictionaryNameValueCollection() | ||
: this(new Dictionary<string, StringValues>()) | ||
{ | ||
} | ||
|
||
public StringValuesReadOnlyDictionaryNameValueCollection(IReadOnlyDictionary<string, StringValues> values) | ||
{ | ||
_values = values; | ||
IsReadOnly = true; | ||
} | ||
|
||
public override string?[] AllKeys => _values.Keys.ToArray(); | ||
|
||
public override int Count => _values.Count; | ||
|
||
public override string[]? GetValues(string? name) | ||
=> name is not null && _values.TryGetValue(name, out var values) ? values : default; | ||
|
||
public override string? Get(string? name) | ||
=> name is not null && _values.TryGetValue(name, out var values) ? values : default; | ||
|
||
public override IEnumerator GetEnumerator() => _values.Keys.GetEnumerator(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/SystemWebAdapters/src/Internal/WrappingNameValueCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Specialized; | ||
|
||
namespace System.Web.Internal | ||
{ | ||
internal abstract class WrappingNameValueCollection : NameValueCollection | ||
{ | ||
private const string IndexErrorMessage = "ASP.NET Core doesn't support accessing server variables by index."; | ||
|
||
public sealed override string? Get(int index) => throw new PlatformNotSupportedException(IndexErrorMessage); | ||
|
||
public sealed override string? GetKey(int index) => throw new PlatformNotSupportedException(IndexErrorMessage); | ||
|
||
public sealed override string[]? GetValues(int index) => throw new PlatformNotSupportedException(IndexErrorMessage); | ||
|
||
public sealed override KeysCollection Keys => throw new PlatformNotSupportedException("KeysCollection is not supported as Get(int) is not available."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.