Ben bir dosyadan StreamReader
oluşturur aşağıdaki yöntemi GetData
var.Temel Akışını Tasfiye Edersem XmlReader'ı İmha Etmem Gerekir mi?
public XmlDocument LoadDocument(Stream file)
{
XmlDocument xmldoc = new XmlDocument();
XmlReader xmlread = XmlReader.Create(file);
xmldoc.Load(xmlread);
return xmldoc;
}
StreamReader
GetData
tarafından elden:
private void GetData(string file)
{
string filename = Path.GetFileNameWithoutExtension(file);
XmlDocument xmldoc = new XmlDocument();
using (StreamReader sr = new StreamReader(file))
{
Stream bs = sr.BaseStream;
Stream cl = mainParser.CleanMarkup(bs);
try
{
xmldoc = mainParser.LoadDocument(bs);
}
catch (XmlException ex)
{
// Exceptions are usually caused by non-compliant documents.
// These errors are not critical to the operation of this program.
Console.WriteLine(filename + " " + ex.Message);
}
}
Msdn msdnParser = new Msdn(xmldoc);
ListViewItem lvitem = new ListViewItem(filename);
lvitem.SubItems.Add(filename);
foreach (string item in msdnParser.Subitems)
{
lvitem.SubItems.Add(item);
}
listView.Items.Add(lvitem);
}
mainParser.LoadDocument(bs)
aşağıdaki çağırır. Bu, XmlReader
'u imha etmek zorunda olmadığım anlamına gelir (bu, inanıyorum), bunun tek yönetilmeyen kaynağını bertaraf edeceğinden?
Ahh, bu iyi bir nokta. Bu muhtemelen farkında olmam gereken bir kavramdır. Yüzümde bir örnek belirdiğinde her zaman güzel olur. –
Ah cevap sadece C# için iyidir. Cevabın C++/CLI'ye bile uygulanabilmesi güzel olurdu. – user3454439