Why Strongly Typed DataSets generated by MS tool don't close streams?
本问题已经有最佳答案,请猛点这里访问。
我刚刚在xsd数据集中找到了该方法。
1 2 3 4 5 6 7 | [System.Diagnostics.DebuggerNonUserCodeAttribute()] protected override System.Xml.Schema.XmlSchema GetSchemaSerializable() { global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream(); this.WriteXmlSchema(new global::System.Xml.XmlTextWriter(stream, null)); stream.Position = 0; return global::System.Xml.Schema.XmlSchema.Read(new global::System.Xml.XmlTextReader(stream), null); } |
它创建3个流,但不使用"使用"子句/将其关闭。 这是为什么?
它还说,在文件的顶部,
1 2 | // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. |
所以我相信我不应该自己修复它。 谁能解释? :) 谢谢
生成的代码不是创建三个流,而是创建一个流,一个流编写器和一个流读取器。"流"只是一个
通常,
请注意,我并不是在主张不要丢弃内存流。对任何
编辑:
尊敬的约翰·斯基特(John Skeet)提出了类似的问题:
https://stackoverflow.com/a/234257/119549