Ejemplo n.º 1
0
        public static XmlReader GetAsXmlReader(ITagAttribute attribute, TagModel model, string fallBack)
        {
            XmlReader reader = null;
            object    raw    = Get(attribute, model) ?? fallBack;

            if (raw == null)
            {
                return(reader);
            }
            if (raw is string && !String.IsNullOrEmpty((string)raw))
            {
                var textReader = new StringReader((string)raw);
                reader = XmlReader.Create(textReader);
            }
            else if (raw is Stream)
            {
                XmlReader.Create((Stream)raw);
            }
            else if (raw is TextReader)
            {
                reader = XmlReader.Create((TextReader)raw);
            }
            else if (raw is XmlReader)
            {
                reader = (XmlReader)raw;
            }
            else
            {
                throw TagException.UnsupportedInput(raw.GetType(), typeof(string), typeof(Stream), typeof(TextReader),
                                                    typeof(XmlReader)).Decorate(attribute.Context);
            }

            return(reader);
        }
Ejemplo n.º 2
0
        public static XPathDocument GetAsXmlDocument(ITagAttribute attribute, TagModel model, string fallBack)
        {
            XPathDocument xDoc = null;
            object        raw  = Get(attribute, model) ?? fallBack;

            if (raw == null)
            {
                return(xDoc);
            }

            if (raw is XPathDocument)
            {
                xDoc = (XPathDocument)raw;
            }
            else if (raw is string)
            {
                if (!String.IsNullOrEmpty((string)raw))
                {
                    var rawAsString = (string)raw;
                    using (var textReader = new StringReader(rawAsString.Trim()))
                    {
                        xDoc = new XPathDocument(textReader);
                    }
                }
                else
                {
                    xDoc = null;
                }
            }
            else if (raw is Stream)
            {
                xDoc = new XPathDocument((Stream)raw);
            }
            else if (raw is TextReader)
            {
                xDoc = new XPathDocument((TextReader)raw);
            }
            else if (raw is XmlReader)
            {
                xDoc = new XPathDocument((XmlReader)raw);
            }
            else
            {
                throw TagException.UnsupportedInput(raw.GetType(), typeof(XPathDocument), typeof(string),
                                                    typeof(Stream), typeof(TextReader),
                                                    typeof(XmlReader)).Decorate(attribute.Context);
            }

            return(xDoc);
        }