파일에서 StreamReader
을 만드는 다음의 메서드 GetData
가 있습니다.기본 스트림을 삭제하면 XmlReader를 삭제해야합니까?
public XmlDocument LoadDocument(Stream file)
{
XmlDocument xmldoc = new XmlDocument();
XmlReader xmlread = XmlReader.Create(file);
xmldoc.Load(xmlread);
return xmldoc;
}
StreamReader
는 GetData
으로 배치된다
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)
은 다음 호출한다. 이것은 XmlReader
을 처리 할 필요가 없다는 뜻인가요? (이것은 믿을만합니다) 유일한 관리되지 않는 리소스를 처리하겠습니까?
아, 좋은 지적입니다. 이것은 아마도 내가 알고 있어야하는 개념 일 것입니다. 예를 들어 내 얼굴에 나타나면 항상 좋습니다. –
아 답은 C#에만 좋습니다. 대답이 C++/CLI에도 적용될 수 있다면 좋을 것입니다. – user3454439