Ejemplo n.º 1
0
        /// <summary>
        /// Load script from string
        /// </summary>
        /// <param name="scriptXml">script as XML</param>
        public void Load(string scriptXml)
        {
            Items.Clear();
            bool close = true;
            var  r     = new ParsingReader(new StringReader(scriptXml));

            try
            {
                r.SkipWhiteSpace();
                if (r.Peek() == '<')
                {
                    // Get a script file
                    XmlReaderSettings rs = new XmlReaderSettings();
                    rs.IgnoreWhitespace = false;
                    rs.ValidationType   = ValidationType.None;

                    using (XmlReader xr = XmlReader.Create(r, new XmlReaderSettings()
                    {
                        ConformanceLevel = ConformanceLevel.Fragment
                    }))
                    {
                        close = false;
                        Load(xr);
                        return;
                    }
                }


                if (r.Peek() == '=')
                {
                    r.Read();
                    Items.Add(new Eval {
                        Value = r.ReadToEnd()
                    });
                    return;
                }
                Items.Add(new Code {
                    Value = r.ReadToEnd()
                });
                return;
            }
            finally
            {
                if (close)
                {
                    r.Close();
                }
            }
        }