From 082d35aa1e8222fe0e33a4f35e590fefdec51a0c Mon Sep 17 00:00:00 2001 From: Greg Young Date: Fri, 29 Jul 2016 05:46:51 +0100 Subject: [PATCH] Using? (#2) minor code optimization with using statement --- .../DBEngine/Management/ManagementServer.cs | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/Src/Core/DBEngine/Management/ManagementServer.cs b/Src/Core/DBEngine/Management/ManagementServer.cs index a1e42eb..2aff00e 100644 --- a/Src/Core/DBEngine/Management/ManagementServer.cs +++ b/Src/Core/DBEngine/Management/ManagementServer.cs @@ -771,42 +771,10 @@ private void SaveConfiguration(object[] nodeConfiguration) private void WriteXMLToFile(string xml) { - System.IO.StreamWriter sw = null; - System.IO.FileStream fs = null; - try - { - fs = new System.IO.FileStream(_fileName, System.IO.FileMode.Create); - sw = new System.IO.StreamWriter(fs); - sw.Write(xml); - sw.Flush(); - } - catch (Exception e) - { - throw e; - } - finally - { - if (sw != null) - { - try - { - sw.Close(); - } - catch (Exception) - { } - sw.Dispose(); - sw = null; - } - if (fs != null) - { - try - { - fs.Close(); - } - catch (Exception) - { } - fs.Dispose(); - fs = null; + using(var fs = new System.IO.FileStream(_fileName, System.IO.FileMode.Create)) { + using(var sw = new System.IO.StreamWriter(fs)) { + sw.Write(xml); + sw.Flush(); } } }