Cake.Web.Core.Content.Documentation.TopicReader.ReadTopic C# (CSharp) Метод

ReadTopic() приватный Метод

private ReadTopic ( XmlReader reader, DirectoryPath root ) : Topic
reader XmlReader
root DirectoryPath
Результат Topic
        private Topic ReadTopic(XmlReader reader, DirectoryPath root)
        {
            var file = reader.GetAttribute("file");
            var url = reader.GetAttribute("importurl");
            if (string.IsNullOrWhiteSpace(file) &&
                string.IsNullOrWhiteSpace(url))
            {
                return null;
            }

            var id = reader.GetAttribute("id");
            var title = reader.GetAttribute("title");
            var hidden = string.Equals("true", reader.GetAttribute("hidden"), StringComparison.OrdinalIgnoreCase);

            if (string.IsNullOrWhiteSpace(id))
            {
                if (!string.IsNullOrWhiteSpace(url))
                {
                    throw new InvalidOperationException("A remote document require a local ID.");
                }
                if (!string.IsNullOrWhiteSpace(file))
                {
                    id = Path.GetFileNameWithoutExtension(file);
                }
                else if(!string.IsNullOrWhiteSpace(title))
                {
                    id = title.ToSlug();
                }
                else
                {
                    throw new InvalidOperationException("Could not generate ID from topic.");
                }
            }

            var body = ReadBody(root, file, url) ?? string.Empty;
            if (!string.IsNullOrWhiteSpace(body))
            {
                // Read the file and separate front matter from content.
                var content = _contentParser.ParseString(body);
                if (content != null)
                {
                    body = _contentProcessor.PreProcess(content.Body);
                    body = _contentConverter.ConvertToHtml(content, body);
                }

                // Process the content.
                body = _contentProcessor.PostProcess(body) ?? body;
            }

            return new Topic(id, title, body, hidden, file, url);
        }