C#6 Cleanup & Optimizations
The main intent is cleanup using C# 6 operators and normalization of type aliases. While there are no intended functional changes here, it does eliminate a few tight race conditions as a bonus (not a real-win since this isn't thread-safe all over, simply noting).
This commit is contained in:
parent
466ca57d4b
commit
6874b87f13
|
|
@ -88,7 +88,6 @@ namespace Microsoft.AspNet.Http
|
|||
/// <summary>
|
||||
/// The file collection sent with the request.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns>The files included with the request.</returns>
|
||||
IFormFileCollection Files { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Encodings.Web;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
|
|
@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Http
|
|||
/// <summary>
|
||||
/// Represents the empty path. This field is read-only.
|
||||
/// </summary>
|
||||
public static readonly PathString Empty = new PathString(String.Empty);
|
||||
public static readonly PathString Empty = new PathString(string.Empty);
|
||||
|
||||
private readonly string _value;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Http
|
|||
/// <summary>
|
||||
/// Represents the empty query string. This field is read-only.
|
||||
/// </summary>
|
||||
public static readonly QueryString Empty = new QueryString(String.Empty);
|
||||
public static readonly QueryString Empty = new QueryString(string.Empty);
|
||||
|
||||
private readonly string _value;
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Http
|
|||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1057:StringUriOverloadsCallSystemUriOverloads", Justification = "Delimiter characters ? and # must be escaped by this method instead of truncating the value")]
|
||||
public static QueryString FromUriComponent(string uriComponent)
|
||||
{
|
||||
if (String.IsNullOrEmpty(uriComponent))
|
||||
if (string.IsNullOrEmpty(uriComponent))
|
||||
{
|
||||
return new QueryString(string.Empty);
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ namespace Microsoft.AspNet.Http
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return (_value != null ? _value.GetHashCode() : 0);
|
||||
return _value?.GetHashCode() ?? 0;
|
||||
}
|
||||
|
||||
public static bool operator ==(QueryString left, QueryString right)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http.Extensions;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Headers
|
||||
|
|
|
|||
|
|
@ -83,11 +83,7 @@ namespace Microsoft.AspNet.Http.Internal
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Store == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Store.Count;
|
||||
return Store?.Count ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,12 +72,7 @@ namespace Microsoft.AspNet.Http.Internal
|
|||
|
||||
if (StringValues.IsNullOrEmpty(value))
|
||||
{
|
||||
if (Store == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Store.Remove(key);
|
||||
Store?.Remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -110,11 +105,7 @@ namespace Microsoft.AspNet.Http.Internal
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Store == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return Store.Count;
|
||||
return Store?.Count ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -195,11 +186,7 @@ namespace Microsoft.AspNet.Http.Internal
|
|||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
if (Store == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Store.Clear();
|
||||
Store?.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Http.Internal
|
|||
get
|
||||
{
|
||||
var handle = CallContext.LogicalGetData(LogicalDataKey) as ObjectHandle;
|
||||
return handle != null ? handle.Unwrap() as HttpContext : null;
|
||||
return handle?.Unwrap() as HttpContext;
|
||||
}
|
||||
set
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Http.Features.Authentication;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace Microsoft.AspNet.Owin
|
||||
{
|
||||
|
|
@ -45,14 +44,11 @@ namespace Microsoft.AspNet.Owin
|
|||
SupportsWebSockets = true;
|
||||
|
||||
var register = Prop<Action<Action<object>, object>>(OwinConstants.CommonKeys.OnSendingHeaders);
|
||||
if (register != null)
|
||||
register?.Invoke(state =>
|
||||
{
|
||||
register(state =>
|
||||
{
|
||||
var collection = (OwinFeatureCollection)state;
|
||||
collection._headersSent = true;
|
||||
}, this);
|
||||
}
|
||||
var collection = (OwinFeatureCollection)state;
|
||||
collection._headersSent = true;
|
||||
}, this);
|
||||
}
|
||||
|
||||
T Prop<T>(string key)
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Owin
|
|||
options = acceptContext.Options;
|
||||
_subProtocol = acceptContext.SubProtocol;
|
||||
}
|
||||
else if (context != null && context.SubProtocol != null)
|
||||
else if (context?.SubProtocol != null)
|
||||
{
|
||||
options = new Dictionary<string, object>(1)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ namespace Microsoft.AspNet.WebUtilities
|
|||
// Special-case empty input
|
||||
if (count == 0)
|
||||
{
|
||||
return String.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// We're going to use base64url encoding with no padding characters.
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
return SupportsMultipleValues;
|
||||
}
|
||||
|
||||
T result = default(T);
|
||||
T result;
|
||||
var length = GetParsedValueLength(value, current, out result);
|
||||
|
||||
if (length == 0)
|
||||
|
|
|
|||
|
|
@ -369,7 +369,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
return 0;
|
||||
}
|
||||
|
||||
nameValueList.Add(nameValue as NameValueHeaderValue);
|
||||
nameValueList.Add(nameValue);
|
||||
}
|
||||
|
||||
// If we get here, we were able to successfully parse the string as list of name/value pairs. Now analyze
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Globalization;
|
||||
|
|
@ -37,11 +36,11 @@ namespace Microsoft.Net.Http.Headers
|
|||
|
||||
// If a parser returns 'null', it means there was no value, but that's valid (e.g. "Accept: "). The caller
|
||||
// can ignore the value.
|
||||
T result = default(T);
|
||||
T result;
|
||||
if (!TryParseValue(value, ref index, out result))
|
||||
{
|
||||
throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Invalid value '{0}'.",
|
||||
value == null ? "<null>" : value.Substring(index)));
|
||||
value?.Substring(index) ?? "<null>"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -114,7 +113,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
else
|
||||
{
|
||||
throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Invalid values '{0}'.",
|
||||
values == null ? "<null>" : value.Substring(index)));
|
||||
value.Substring(index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,13 +64,13 @@ namespace Microsoft.Net.Http.Headers
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!String.Equals(stringWithQuality1.Value, stringWithQuality2.Value, StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(stringWithQuality1.Value, stringWithQuality2.Value, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (String.Equals(stringWithQuality1.Value, "*", StringComparison.Ordinal))
|
||||
if (string.Equals(stringWithQuality1.Value, "*", StringComparison.Ordinal))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (String.Equals(stringWithQuality2.Value, "*", StringComparison.Ordinal))
|
||||
else if (string.Equals(stringWithQuality2.Value, "*", StringComparison.Ordinal))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
public void CookieHeaderValue_Value()
|
||||
{
|
||||
var cookie = new CookieHeaderValue("name");
|
||||
Assert.Equal(String.Empty, cookie.Value);
|
||||
Assert.Equal(string.Empty, cookie.Value);
|
||||
|
||||
cookie.Value = "value1";
|
||||
Assert.Equal("value1", cookie.Value);
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ namespace Microsoft.Net.Http.Headers
|
|||
public void SetCookieHeaderValue_Value()
|
||||
{
|
||||
var cookie = new SetCookieHeaderValue("name");
|
||||
Assert.Equal(String.Empty, cookie.Value);
|
||||
Assert.Equal(string.Empty, cookie.Value);
|
||||
|
||||
cookie.Value = "value1";
|
||||
Assert.Equal("value1", cookie.Value);
|
||||
|
|
|
|||
Loading…
Reference in New Issue