Ejemplo n.º 1
0
        public static CodeSnippet FromFile(string aFile)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(aFile);
            CodeSnippet ret = new CodeSnippet();
            ret.Name = doc.DocumentElement.GetAttribute("name");
            ret.Extension = doc.DocumentElement.GetAttribute("extension");

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("option"))
            {
                CodeSnippetOption opt = new CodeSnippetOption { Name = elem.GetAttribute("name"), Key = elem.GetAttribute("key") };
                ret.Inputs.Add(opt);
            }

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("input")) {
                CodeSnippetInput input = new CodeSnippetInput();
                input.Name = elem.GetAttribute("name");
                input.Key = elem.GetAttribute("key");
                ret.Inputs.Add(input);
            }
            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("code")) {
                string requires = elem.GetAttribute("requires");
                if (requires != null && requires.Length > 0)
                {
                    ret.Code.Add(new CodeBlock { Code = elem.InnerText, Requires = requires.Split(' ') });
                }
                else
                    ret.Code.Add(new CodeBlock { Code = elem.InnerText, Requires = null });
            }
            return ret;
        }
Ejemplo n.º 2
0
        public static CodeSnippet FromFile(string aFile)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(aFile);
            CodeSnippet ret = new CodeSnippet();

            ret.Name      = doc.DocumentElement.GetAttribute("name");
            ret.Extension = doc.DocumentElement.GetAttribute("extension");

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("option"))
            {
                CodeSnippetOption opt = new CodeSnippetOption {
                    Name = elem.GetAttribute("name"), Key = elem.GetAttribute("key")
                };
                ret.Inputs.Add(opt);
            }

            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("input"))
            {
                CodeSnippetInput input = new CodeSnippetInput();
                input.Name = elem.GetAttribute("name");
                input.Key  = elem.GetAttribute("key");
                ret.Inputs.Add(input);
            }
            foreach (XmlElement elem in doc.DocumentElement.GetElementsByTagName("code"))
            {
                string requires = elem.GetAttribute("requires");
                if (requires != null && requires.Length > 0)
                {
                    ret.Code.Add(new CodeBlock {
                        Code = elem.InnerText, Requires = requires.Split(' ')
                    });
                }
                else
                {
                    ret.Code.Add(new CodeBlock {
                        Code = elem.InnerText, Requires = null
                    });
                }
            }
            return(ret);
        }