Created extension method to check source is not null and not empty
MODIFY
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
@@ -81,7 +81,7 @@ namespace System.Net.Http
var startLine = new RequestLine(me.Method, me.RequestUri, new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}")).ToString();
string headers = "";
- if (me.Headers != null && me.Headers.Any())
+ if (me.Headers.NotNullAndNotEmpty())
{
var headerSection = HeaderSection.CreateNew(me.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);
@@ -90,7 +90,7 @@ namespace System.Net.Http
string messageBody = "";
if (me.Content != null)
{
- if (me.Content.Headers != null && me.Content.Headers.Any())
+ if (me.Content.Headers.NotNullAndNotEmpty())
{
var headerSection = HeaderSection.CreateNew(me.Content.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);

MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -65,7 +65,7 @@ namespace System.Net.Http
var startLine = new StatusLine(new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}"), me.StatusCode).ToString();
var headers = "";
- if (me.Headers != null && me.Headers.Any())
+ if (me.Headers.NotNullAndNotEmpty())
{
var headerSection = HeaderSection.CreateNew(me.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);
@@ -74,7 +74,7 @@ namespace System.Net.Http
var messageBody = "";
if (me.Content != null)
{
- if (me.Content.Headers != null && me.Content.Headers.Any())
+ if (me.Content.Headers.NotNullAndNotEmpty())
{
var headerSection = HeaderSection.CreateNew(me.Content.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);

MODIFY
WalletWasabi/Extensions/LinqExtensions.cs
WalletWasabi/Extensions/LinqExtensions.cs
@@ -56,5 +56,10 @@ namespace System.Linq
me.Remove(item);
}
}
+
+ public static bool NotNullAndNotEmpty<T>(this IEnumerable<T> source)
+ {
+ return source != null && source.Any();
+ }
}
}

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -492,7 +492,7 @@ namespace System.Net.Http
public static HttpContent GetDummyOrNullContent(HttpContentHeaders contentHeaders)
{
- if (contentHeaders != null && contentHeaders.Any())
+ if (contentHeaders.NotNullAndNotEmpty())
{
return new ByteArrayContent(new byte[] { }); // dummy empty content
}
@@ -504,7 +504,7 @@ namespace System.Net.Http
public static void CopyHeaders(HttpHeaders source, HttpHeaders destination)
{
- if (source != null && source.Any())
+ if (source.NotNullAndNotEmpty())
{
foreach (var header in source)
{

Created extension method to check source is not null and not empty