示例#1
0
        public void ParseScriptComments(string path)
        {
            var tree = SyntaxTree.ParseFile(path, ParseOptions.Default.WithParseDocumentationComments(true));

            var compilation = Compilation.Create("comments", syntaxTrees: new[] { tree });
            var classSymbol = compilation.GlobalNamespace.GetMembers().FirstOrDefault();

            if (classSymbol != null)
            {
                var            doc      = classSymbol.GetDocumentationComment();
                XDocument      comments = XDocument.Parse(string.Format("{0}{1}{2}", "<root>", doc.FullXmlFragmentOpt, "</root>"));
                ScriptMetadata metadata = new ScriptMetadata();

                var name = Path.GetFileNameWithoutExtension(path);
                if (!string.IsNullOrWhiteSpace(name))
                {
                    metadata.Name = name;
                }

                metadata.Description   = ParseNode(comments, "description");
                metadata.Configuration = ParseNode(comments, "configuration");
                metadata.Author        = ParseNode(comments, "author");
                metadata.Notes         = ParseNode(comments, "notes");

                var commands = comments.Descendants("commands").FirstOrDefault();
                if (commands != null && !string.IsNullOrWhiteSpace(commands.Value))
                {
                    metadata.Commands = commands.Value.Split(';').Select(d => d.Trim()).ToList();
                }

                _robot.AddMetadata(metadata);
            }
        }
示例#2
0
        public void ParseScriptComments(string path)
        {
            var tree = SyntaxTree.ParseFile(path, ParseOptions.Default.WithParseDocumentationComments(true));

            var compilation = Compilation.Create("comments", syntaxTrees: new[] { tree });
            var classSymbol = compilation.GlobalNamespace.GetMembers().FirstOrDefault();
            if (classSymbol != null)
            {
                var doc = classSymbol.GetDocumentationComment();
                XDocument comments = XDocument.Parse(string.Format("{0}{1}{2}", "<root>", doc.FullXmlFragmentOpt, "</root>"));                    
                ScriptMetadata metadata = new ScriptMetadata();
                
                var name = Path.GetFileNameWithoutExtension(path);
                if (!string.IsNullOrWhiteSpace(name))
                    metadata.Name = name;

                metadata.Description = ParseNode(comments, "description");
                metadata.Configuration = ParseNode(comments, "configuration");
                metadata.Author = ParseNode(comments, "author");
                metadata.Notes = ParseNode(comments, "notes");

                var commands = comments.Descendants("commands").FirstOrDefault();
                if (commands != null && !string.IsNullOrWhiteSpace(commands.Value))
                    metadata.Commands = commands.Value.Split(';').Select(d => d.Trim()).ToList();

                _robot.AddMetadata(metadata);
            }
        }