Esempio n. 1
0
        public App()
        {
            MyElement elem = (MyElement)Document.GetElementById("foo");
            string    s    = elem.myString;

            elem["Smith"] = elem["Joe"];

            int         n   = Math.Truncate(5.5);
            XmlDocument doc = XmlDocumentParser.Parse("<markup></markup>");
            Date        d   = Date.Parse("1/1/2010");
        }
Esempio n. 2
0
        public void GivenDocumentWithConstant_WhenParseDocument_ThenSchemaHasRootWithConstant()
        {
            // given
            var document = Resources.ResourceManager.GetString("XMLDocumentWithConstant");

            // when
            var parser = new XmlDocumentParser();
            var schema = parser.Parse(document);

            // then
            Assert.AreEqual(schema.Root.Children.Count, 1);
            Assert.IsInstanceOf <SchemaConstant>(schema.Root.Children[0]);
        }
Esempio n. 3
0
            public static void Parse(SymbolDescriptionProvider provider, ISymbol symbol)
            {
                var rawXml  = "<i>" + symbol.GetDocumentationCommentXml() + "</i>";
                var comment = new XmlDocumentParser(provider, symbol);

                XDocument doc = null;

                try
                {
                    doc = XDocument.Parse(rawXml);
                }
                catch (XmlException)
                {
                    return;
                }

                comment.Parse(doc);
            }
Esempio n. 4
0
        public void GivenTwoElementsWithTwoAttributesEach_WhenParseDocument_ThenSchemaHasTwoElementsWithTwoAttributesEach()
        {
            // given
            var document = Resources.ResourceManager.GetString("XMLDocumentWithTwoElements");

            // when
            var parser = new XmlDocumentParser();
            var schema = parser.Parse(document);

            // then
            Assert.AreEqual(schema.Root.Children.Count, 2);
            var firstElement = schema.Root.Children[0];

            Assert.AreEqual(firstElement.Attributes.Count, 2);
            var secondElement = schema.Root.Children[1];

            Assert.AreEqual(secondElement.Attributes.Count, 2);
        }
Esempio n. 5
0
        private void OnBeautifyByMeClick(object sender, EventArgs e)
        {
            var text = _currentFileStatus.Text;

            if (string.IsNullOrEmpty(text))
            {
                _warningShower.Show("I can't beautify emptiness");
                return;
            }

            // try
            // {
            var parser = new XmlDocumentParser();
            var schema = parser.Parse(text);

            _currentFileStatus.Text = parser.Stringify(schema);
            // }
            // catch (ParseException ex)
            // {
            //     _warningShower.Show($"Invalid xml document: {ex.Message}");
            // }
        }
        static void Generate()
        {
            var selections = Selection.GetFiltered(typeof(TextAsset), SelectionMode.DeepAssets);

            if (selections == null || selections.Length <= 0)
            {
                return;
            }

            var    dir       = EditorPrefs.GetString(OUTPUT_DIR_KEY, DEFAULT_OUTPUT_DIR);
            var    className = EditorPrefs.GetString(CLASS_NAME_KEY, DEFAULT_CLASS_NAME);
            string location  = EditorUtility.SaveFilePanel("Generate Code", dir, className, "cs");

            if (string.IsNullOrEmpty(location))
            {
                return;
            }

            dir       = GetRelativeDirectory(location);
            className = GetClassName(location);

            EditorPrefs.SetString(OUTPUT_DIR_KEY, dir);
            EditorPrefs.SetString(CLASS_NAME_KEY, className);

            CodeGenerator               generator = new CodeGenerator();
            XmlDocumentParser           parser    = new XmlDocumentParser();
            Dictionary <string, object> data      = new Dictionary <string, object> ();

            foreach (var s in selections)
            {
                try {
                    string path = AssetDatabase.GetAssetPath(s);
                    if (!path.ToLower().EndsWith(EXTENSION))
                    {
                        continue;
                    }

                    var dict = parser.Parse(new MemoryStream((s as TextAsset).bytes));
                    foreach (KeyValuePair <string, object> kv in dict)
                    {
                        data [kv.Key] = kv.Value;
                    }
                } catch (Exception) {
                }
            }
            if (data.Count <= 0)
            {
                return;
            }

            var code = generator.Generate(className, data);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllText(location, code);

            AssetDatabase.Refresh();
        }
Esempio n. 7
0
 public static XmlDocument ParseXml(string xml)
 {
     return(XmlDocumentParser.Parse(xml));
 }