コード例 #1
0
        public static string GetSubElementAtPosition(ProjectType projectType, string fileName, ITextSnapshot snapshot, string xaml, int position, ILogger logger, string projectFile, IVisualStudioAbstraction vsAbstraction)
        {
            var startPos = xaml.LastIndexOf('<', position, position);

            var elementName = GetElementName(xaml.AsSpan(), startPos);

            string result = null;

            var processor = new SubElementProcessor(new ProcessorEssentials(projectType, logger, projectFile, vsAbstraction));

            processor.SubElementFound += (s, e) => { result = e.SubElement; };

            XamlElementExtractor.Parse(projectType, fileName, snapshot, xaml.Substring(startPos), new List <(string element, XamlElementProcessor processor)> {
                (elementName, processor),
            }, new TagList(), vsAbstraction, skipEveryElementProcessor: true);

#if DEBUG
            if (result == null)
            {
                // If get here it's because there's a subelement that can't be identified correctly by XamlElementExtractor
                // but was detected elsewhere. (Probably by something extending XamlElementProcessor.)
                System.Diagnostics.Debugger.Break();
            }
#endif

            return(result);
        }
コード例 #2
0
        public static string GetSubElementAtPosition(ProjectType projectType, string fileName, ITextSnapshot snapshot, string xaml, int position, ILogger logger)
        {
            var startPos = xaml.Substring(0, position).LastIndexOf('<');

            var elementName = xaml.Substring(startPos + 1, xaml.IndexOfAny(new[] { ' ', '>', '\r', '\n' }, startPos) - startPos - 1);

            string result = null;

            var processor = new SubElementProcessor(projectType, logger);

            processor.SubElementFound += (s, e) => { result = e.SubElement; };

            XamlElementExtractor.Parse(projectType, fileName, snapshot, xaml.Substring(startPos), new List <(string element, XamlElementProcessor processor)> {
                (elementName, processor),
            }, new TagList());

#if DEBUG
            if (result == null)
            {
                // If get here it's because there's a subelement that can't be identified correctly by XamlElementExtractor
                // but was detected elsewhere. (Probably by something extending XamlElementProcessor.)
                System.Diagnostics.Debugger.Break();
            }
#endif

            return(result);
        }
コード例 #3
0
        public static string GetSubElementAtPosition(string xaml, int position)
        {
            var startPos = xaml.Substring(0, position).LastIndexOf('<');

            var elementName = xaml.Substring(startPos + 1, xaml.IndexOfAny(new[] { ' ', '>' }, startPos) - startPos - 1);

            string result = null;

            var processor = new SubElementProcessor();

            processor.SubElementFound += (s, e) => { result = e.SubElement; };

            XamlElementExtractor.Parse(null, xaml.Substring(startPos), new List <(string element, XamlElementProcessor processor)> {
                (elementName, processor),
            }, new List <IRapidXamlAdornmentTag>());

            return(result);
        }
コード例 #4
0
 /// <summary>
 /// process an xml element when reading an xml stream
 /// </summary>
 /// <param name="reader">the reader</param>
 /// <param name="elementName">the name of the element we are processing</param>
 /// <param name="subElementProcessor">a delegate to process any sub elements detected</param>
 public static void ProcessElement(XmlReader reader, string elementName, SubElementProcessor subElementProcessor)
 {
     if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == elementName)
     {
         reader.Read(); // Skip ahead to next node
         var element = reader.MoveToContent();
         while (element != XmlNodeType.None)
         {
             if (element == XmlNodeType.EndElement && reader.LocalName == elementName)
             {
                 break;
             }
             if (reader.IsStartElement())
             {
                 subElementProcessor(reader);
             }
             reader.Read();
             element = reader.MoveToContent();
         }
     }
 }