Commits

Matt Hamilton committed aae8fa3

Fixing CA2202 warnings

Comments (0)

Files changed (2)

Budgie/Extensions/WebResponseExtensions.cs

 
         public static string GetContentString(this WebResponse response)
         {
-            using (var stream = response.GetResponseStream())
-            using (var reader = new StreamReader(stream))
-                return reader.ReadToEnd();
+            // not "using" rs as per CA2202
+            Stream stream = null;
+            try
+            {
+                stream = response.GetResponseStream();
+                using (var reader = new StreamReader(stream))
+                {
+                    stream = null;
+                    return reader.ReadToEnd();
+                }
+            }
+            finally
+            {
+                if (stream != null) stream.Dispose();
+            }
         }
     }
 }

Budgie/TwitterAnonymousClient.Http.cs

 
             if (content != null)
             {
-                using (var rs = request.GetRequestStream())
+                // not "using" rs as per CA2202
+                Stream rs = null;
+                try
                 {
-                    using (var sw = new StreamWriter(rs)) sw.Write(content);
+                    rs = request.GetRequestStream();
+                    using (var sw = new StreamWriter(rs))
+                    {
+                        rs = null;
+                        sw.Write(content);
+                    }
+                }
+                finally
+                {
+                    if (rs != null) rs.Dispose();
                 }
             }