Пример #1
0
        internal static AllplanAttributesContainer ReadFrom(XmlReader reader)
        {
            if (reader.NodeType != XmlNodeType.Element)
            {
                throw new NotSupportedException($"Expecting element type");
            }
            if (!reader.Name.Equals(ELEMENT_NAME))
            {
                throw new NotSupportedException($"Expecting '{ELEMENT_NAME}' as prefix. Got '{reader.Name}'");
            }

            var container = new AllplanAttributesContainer
            {
                Version  = reader.GetAttribute("VERSION"),
                FileType = reader.GetAttribute("FILETYPE")
            };

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    if (reader.Name.Equals(AllplanAttributeSet.ELEMENT_NAME))
                    {
                        container.AttributeSet = AllplanAttributeSet.ReadFrom(reader);
                    }
                    else
                    {
                        throw new NotImplementedException($"Missing implementation for element '{reader.Name}'");
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name.Equals(ELEMENT_NAME))
                    {
                        return(container);
                    }
                    break;
                }
            }
            throw new NotSupportedException($"Unexpected end of file");
        }
Пример #2
0
        public static AllplanAttributesContainer ReadFrom(string fileName)
        {
            using (var reader = XmlReader.Create(File.OpenRead(fileName)))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.Name.Equals(AllplanAttributesContainer.ELEMENT_NAME))
                        {
                            return(AllplanAttributesContainer.ReadFrom(reader));
                        }
                        break;
                    }
                }

                throw new NotSupportedException("Unexpected end of file");
            }
        }