Example #1
0
        public CodeSnippet(XElement codeSnippetElement, string filePath)
        {
            this.FilePath     = filePath;
            this.Fields       = new List <ExpansionField>();
            this.SnippetTypes = new List <string>();

            var header = codeSnippetElement.Element(GetXName("Header"));

            this.Title       = GetElementInnerText(header, "Title");
            this.Shortcut    = GetElementInnerText(header, "Shortcut") ?? ""; // https://github.com/dotnet/roslyn/pull/31738
            this.Description = GetElementInnerText(header, "Description");
            this.Author      = GetElementInnerText(header, "Author");
            var snippetTypes = header.Element(GetXName("SnippetTypes"));

            if (snippetTypes != null)
            {
                var snippetTypeElements = snippetTypes.Elements();
                foreach (var snippetType in snippetTypeElements)
                {
                    SnippetTypes.Add(snippetType.Value);
                }
            }

            Snippet = codeSnippetElement.Element(GetXName("Snippet"));
            var declarations = Snippet.Element(GetXName("Declarations"));

            ReadDeclarations(declarations);
            var code = Snippet.Element(GetXName("Code"));

            this.Code     = code.Value.Replace("\n", "\r\n");
            this.Language = code.Attribute("Language").Value;
        }
        private static IEnumerable <string> GetSnippetTypes(SnippetTypes value)
        {
            if ((value & SnippetTypes.Expansion) != 0)
            {
                yield return(SnippetTypes.Expansion.ToString());
            }

            if ((value & SnippetTypes.SurroundsWith) != 0)
            {
                yield return(SnippetTypes.SurroundsWith.ToString());
            }

            if ((value & SnippetTypes.Refactoring) != 0)
            {
                yield return(SnippetTypes.Refactoring.ToString());
            }
        }
        private static IEnumerable<string> GetSnippetTypes(SnippetTypes value)
        {
            if ((value & SnippetTypes.Expansion) != 0)
                yield return SnippetTypes.Expansion.ToString();

            if ((value & SnippetTypes.SurroundsWith) != 0)
                yield return SnippetTypes.SurroundsWith.ToString();

            if ((value & SnippetTypes.Refactoring) != 0)
                yield return SnippetTypes.Refactoring.ToString();
        }