Skip to content

Commit d2efe94

Browse files
Refactorings per Resharper recommendations
1 parent e80e850 commit d2efe94

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

NScrape/WebResponseFactory.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ public class WebResponseFactory {
1616
/// Initializes static members of the <see cref="WebResponseFactory"/> class.
1717
/// </summary>
1818
static WebResponseFactory() {
19-
SupportedContentTypes = new Dictionary<string, Func<HttpWebResponse, WebResponse>>();
20-
21-
SupportedContentTypes.Add( "image/", CreateImageResponse );
22-
SupportedContentTypes.Add( "text/xml", CreateXmlResponse );
23-
SupportedContentTypes.Add( "application/xml", CreateXmlResponse );
24-
SupportedContentTypes.Add( "text/plain", CreateTextResponse );
25-
SupportedContentTypes.Add( "text/javascript", CreateJavaScriptResponse );
26-
SupportedContentTypes.Add( "application/javascript ", CreateJavaScriptResponse );
27-
SupportedContentTypes.Add( "application/x-javascript", CreateJavaScriptResponse );
28-
SupportedContentTypes.Add( "application/json", CreateJsonResponse );
29-
SupportedContentTypes.Add( "application/octet-stream", CreateBinaryResponse );
19+
SupportedContentTypes = new Dictionary<string, Func<HttpWebResponse, WebResponse>> {
20+
{ "image/", CreateImageResponse },
21+
{ "text/xml", CreateXmlResponse },
22+
{ "application/xml", CreateXmlResponse },
23+
{ "text/plain", CreateTextResponse },
24+
{ "text/javascript", CreateJavaScriptResponse },
25+
{ "application/javascript ", CreateJavaScriptResponse },
26+
{ "application/x-javascript", CreateJavaScriptResponse },
27+
{ "application/json", CreateJsonResponse },
28+
{ "application/octet-stream", CreateBinaryResponse }
29+
};
3030
}
3131

3232
/// <summary>
@@ -100,12 +100,14 @@ public static WebResponse CreateXmlResponse( HttpWebResponse webResponse ) {
100100
/// A new <see cref="BinaryWebResponse"/>.
101101
/// </returns>
102102
public static WebResponse CreateBinaryResponse( HttpWebResponse webResponse ) {
103-
byte[] data;
103+
byte[] data = {};
104104

105105
using ( var s = webResponse.GetResponseStream() ) {
106-
using ( var memoryStream = new MemoryStream() ) {
107-
s.CopyTo( memoryStream );
108-
data = memoryStream.ToArray();
106+
if ( s != null ) {
107+
using ( var memoryStream = new MemoryStream() ) {
108+
s.CopyTo( memoryStream );
109+
data = memoryStream.ToArray();
110+
}
109111
}
110112
}
111113

0 commit comments

Comments
 (0)