Skip to content

Commit 68edc94

Browse files
committed
Merge
2 parents f7e5214 + b2d24d0 commit 68edc94

File tree

13 files changed

+41
-36
lines changed

13 files changed

+41
-36
lines changed

RestSharp/Authenticators/JwtAuthenticator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class JwtAuthenticator : IAuthenticator
3333
public JwtAuthenticator(string accessToken)
3434
{
3535
if (accessToken == null)
36-
throw new ArgumentNullException("accessToken");
36+
throw new ArgumentNullException(nameof(accessToken));
3737

3838
authHeader = string.Format("Bearer {0}", accessToken);
3939
}

RestSharp/Authenticators/NtlmAuthenticator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public NtlmAuthenticator(string username, string password)
5252
/// <param name="credentials"></param>
5353
public NtlmAuthenticator(ICredentials credentials)
5454
{
55-
this.credentials = credentials ?? throw new ArgumentNullException("credentials");
55+
this.credentials = credentials ?? throw new ArgumentNullException(nameof(credentials));
5656
}
5757

5858
public void Authenticate(IRestClient client, IRestRequest request)

RestSharp/Authenticators/OAuth/Extensions/CollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static string ToQueryString(this NameValueCollection collection)
6262

6363
if (collection.Count > 0)
6464
{
65-
sb.Append("?");
65+
sb.Append('?');
6666
}
6767

6868
int count = 0;
@@ -77,7 +77,7 @@ public static string ToQueryString(this NameValueCollection collection)
7777
continue;
7878
}
7979

80-
sb.Append("&");
80+
sb.Append('&');
8181
}
8282

8383
return sb.ToString();

RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ namespace RestSharp.Authenticators.OAuth.Extensions
88
{
99
internal static class StringExtensions
1010
{
11-
public static bool IsNullOrBlank(this string value) => string.IsNullOrEmpty(value) ||
12-
!string.IsNullOrEmpty(value) &&
13-
value.Trim() == string.Empty;
11+
public static bool IsNullOrBlank(this string value) => string.IsNullOrWhiteSpace(value);
1412

15-
public static bool EqualsIgnoreCase(this string left, string right) =>
16-
string.Compare(left, right, StringComparison.OrdinalIgnoreCase) == 0;
13+
public static bool EqualsIgnoreCase(this string left, string right) =>
14+
string.Equals(left, right, StringComparison.OrdinalIgnoreCase);
1715

1816
public static bool EqualsAny(this string input, params string[] args) =>
1917
args.Aggregate(false, (current, arg) => current | input.Equals(arg));
@@ -42,7 +40,7 @@ public static string PercentEncode(this string s)
4240
var sb = new StringBuilder();
4341

4442
foreach (var b in bytes)
45-
sb.Append(string.Format("%{0:X2}", b));
43+
sb.AppendFormat("%{0:X2}", b);
4644

4745
return sb.ToString();
4846
}

RestSharp/Authenticators/OAuth/OAuthTools.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,12 @@ public static WebParameterCollection SortParametersExcludingSignature(WebParamet
177177
p.Name = UrlEncodeStrict(p.Name);
178178
p.Value = UrlEncodeStrict(p.Value);
179179
});
180-
copy.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name) != 0
181-
? string.CompareOrdinal(x.Name, y.Name)
182-
: string.CompareOrdinal(x.Value, y.Value));
180+
copy.Sort((x, y) => {
181+
int compareName = string.CompareOrdinal(x.Name, y.Name);
182+
return (compareName != 0)
183+
? compareName
184+
: string.CompareOrdinal(x.Value, y.Value);
185+
});
183186

184187
return copy;
185188
}
@@ -194,7 +197,7 @@ public static WebParameterCollection SortParametersExcludingSignature(WebParamet
194197
public static string ConstructRequestUrl(Uri url)
195198
{
196199
if (url == null)
197-
throw new ArgumentNullException("url");
200+
throw new ArgumentNullException(nameof(url));
198201

199202
var sb = new StringBuilder();
200203
var requestUrl = "{0}://{1}".FormatWith(url.Scheme, url.Host);

RestSharp/Extensions/ReflectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ public static object ChangeType(this object source, Type newType, CultureInfo cu
9494
/// <returns></returns>
9595
public static object FindEnumValue(this Type type, string value, CultureInfo culture)
9696
{
97+
var caseInsensitiveComparer = StringComparer.Create(culture, true);
98+
9799
Enum ret = Enum.GetValues(type)
98100
.Cast<Enum>()
99101
.FirstOrDefault(v => v.ToString()
100102
.GetNameVariants(culture)
101-
.Contains(value, StringComparer.Create(culture, true)));
103+
.Contains(value, caseInsensitiveComparer));
102104

103105
if (ret != null) return ret;
104106

RestSharp/Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static string ToPascalCase(this string text, bool removeUnderscores, Cult
203203
if (string.IsNullOrEmpty(text))
204204
return text;
205205

206-
text = text.Replace("_", " ");
206+
text = text.Replace('_', ' ');
207207

208208
var joinString = removeUnderscores
209209
? string.Empty

RestSharp/Http.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ private string GetMultipartFormData(HttpParameter param)
288288
private void AppendHeaders(HttpWebRequest webRequest)
289289
{
290290
foreach (var header in Headers)
291-
if (restrictedHeaderActions.ContainsKey(header.Name))
292-
restrictedHeaderActions[header.Name].Invoke(webRequest, header.Value);
291+
if (restrictedHeaderActions.TryGetValue(header.Name, out var restrictedHeaderAction))
292+
restrictedHeaderAction.Invoke(webRequest, header.Value);
293293
else
294294
webRequest.Headers.Add(header.Name, header.Value);
295295
}

RestSharp/RestClient.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public RestClient()
8383
public RestClient(string baseUrl) : this()
8484
{
8585
if (baseUrl.IsEmpty())
86-
throw new ArgumentNullException("baseUrl");
86+
throw new ArgumentNullException(nameof(baseUrl));
8787

8888
BaseUrl = new Uri(baseUrl);
8989
}
@@ -471,7 +471,7 @@ private static IEnumerable<Parameter> GetQueryStringParameters(IRestRequest requ
471471
private Func<IDeserializer> GetHandler(string contentType)
472472
{
473473
if (contentType == null)
474-
throw new ArgumentNullException("contentType");
474+
throw new ArgumentNullException(nameof(contentType));
475475

476476
if (string.IsNullOrEmpty(contentType) && ContentHandlers.ContainsKey("*"))
477477
return ContentHandlers["*"];
@@ -481,8 +481,8 @@ private Func<IDeserializer> GetHandler(string contentType)
481481
if (semicolonIndex > -1)
482482
contentType = contentType.Substring(0, semicolonIndex);
483483

484-
if (ContentHandlers.ContainsKey(contentType))
485-
return ContentHandlers[contentType];
484+
if (ContentHandlers.TryGetValue(contentType, out var contentHandler))
485+
return contentHandler;
486486

487487
// Avoid unnecessary use of regular expressions in checking for structured syntax suffix by looking for a '+' first
488488
if (contentType.IndexOf('+') >= 0)
@@ -493,9 +493,9 @@ private Func<IDeserializer> GetHandler(string contentType)
493493
if (structuredSyntaxSuffixMatch.Success)
494494
{
495495
var structuredSyntaxSuffixWildcard = "*" + structuredSyntaxSuffixMatch.Value;
496-
if (ContentHandlers.ContainsKey(structuredSyntaxSuffixWildcard))
496+
if (ContentHandlers.TryGetValue(structuredSyntaxSuffixWildcard, out var contentHandlerWildcard))
497497
{
498-
return ContentHandlers[structuredSyntaxSuffixWildcard];
498+
return contentHandlerWildcard;
499499
}
500500
}
501501
}
@@ -556,7 +556,7 @@ internal IHttp ConfigureHttp(IRestRequest request)
556556
}
557557

558558
// Add Accept header based on registered deserializers if none has been set by the caller.
559-
if (requestParameters.All(p => p.Name.ToLowerInvariant() != "accept"))
559+
if (requestParameters.All(p => !string.Equals(p.Name, "accept", StringComparison.InvariantCultureIgnoreCase)))
560560
{
561561
var accepts = string.Join(", ", AcceptTypes.ToArray());
562562

RestSharp/RestRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bool InvalidHost(string host)
561561
}
562562

563563
if (name == "Host" && InvalidHost(value))
564-
throw new ArgumentException("The specified value is not a valid Host header string.", "value");
564+
throw new ArgumentException("The specified value is not a valid Host header string.", nameof(value));
565565
return AddParameter(name, value, ParameterType.HttpHeader);
566566
}
567567

0 commit comments

Comments
 (0)