Esempio n. 1
0
        public void Load(string file)
        {
            using (FileStream fs = File.OpenRead(file))
            {
                byte[] buf = new byte[1024];
                int    nread;
                if ((nread = fs.Read(buf, 0, buf.Length)) <= 0)
                {
                    return;
                }
                int i;
                if (ByteOrderMark.TryParse(buf, nread, out this.bom))
                {
                    i = this.bom.Length;
                }
                else
                {
                    i = 0;
                }
                while (true)
                {
                    if (i < nread)
                    {
                        if (buf[i] == 13)
                        {
                            this.newLine = "\r\n";
                        }
                        else
                        {
                            if (buf[i] != 10)
                            {
                                i++;
                                continue;
                            }
                            this.newLine = "\n";
                        }
                    }
                    if (this.newLine == null)
                    {
                        if ((nread = fs.Read(buf, 0, buf.Length)) <= 0)
                        {
                            break;
                        }
                        i = 0;
                    }
                    if (this.newLine != null)
                    {
                        goto IL_A7;
                    }
                }
                this.newLine = "\n";
IL_A7:
                this.endsWithEmptyLine = (fs.Seek(-1L, SeekOrigin.End) > 0L && fs.ReadByte() == 10);
            }
            this.doc = new XmlDocument();
            this.doc.PreserveWhitespace = false;
            string xml = File.ReadAllText(file);

            this.doc.LoadXml(xml);
        }
Esempio n. 2
0
        public static bool TryParse(Stream stream, out ByteOrderMark bom)
        {
            byte[] buffer = new byte[4];
            int    nread;

            if ((nread = stream.Read(buffer, 0, buffer.Length)) < 2)
            {
                bom = null;
                return(false);
            }
            return(ByteOrderMark.TryParse(buffer, nread, out bom));
        }