Example #1
0
        public XmlElementStream(System.IO.Stream sourceStream,
                                System.IO.FileAccess permissions = System.IO.FileAccess.ReadWrite, object owner = null, string streamNameOverride = null)
        {
            Contract.Requires <ArgumentNullException>(sourceStream != null);
            Contract.Requires <ArgumentException>(sourceStream.HasPermissions(permissions));

            if (streamNameOverride.IsNullOrEmpty())
            {
                SetStreamName(sourceStream);
            }
            else
            {
                base.StreamName = streamNameOverride;
            }

            var doc = new Xml.XmlDocumentWithLocation
            {
                FileName = base.StreamName
            };

            Document = doc;
            try
            {
                using (var xmlReader = XmlReader.Create(sourceStream))
                {
                    Document.Load(xmlReader);
                }
            } catch (Exception ex)
            {
                throw new System.IO.InvalidDataException("Failed to load " + StreamName, ex);
            }

            StreamMode = StreamPermissions = permissions;

            this.Owner = owner;
        }