The configuration file of my app is similar to,
<?xml version="1.0" encoding="utf-8" ?>
<Items>
<Item Name="Coffee"
Cost="10"
Image="itemCoffee.png" />
<Item Name="Tea"
Cost="10"
Image="itemTea.png" />
<Item Name="Vada"
Cost="10"
Image="itemVada.png" />
</Items>
Just trying to read the above small configuration file and I wrote this method.
public static class Configuration
{
public static T DeSerialize<T>(string filePath)
{
if (!System.IO.File.Exists(filePath))
{
throw new System.IO.FileNotFoundException(filePath);
}
var serializer = new System.Xml.Serialization.XmlSerializer(T);
return (T)serializer.Deserialize(new FileStream(filePath, FileMode.Open));
}
}
Where should I use
using
in this code? (Because, I never ever dispose thenew FileStream
that I wrote in this method)Is this an overkill for reading this simple xml file?