AvalonStudio.Languages.CPlusPlus.CPlusPlusLanguageService.ApplyReplacements C# (CSharp) 메소드

ApplyReplacements() 공개 정적인 메소드

public static ApplyReplacements ( TextDocument document, int cursor, System.Xml.Linq.XDocument replacements, bool replaceCursor = true ) : int
document AvalonStudio.TextEditor.Document.TextDocument
cursor int
replacements System.Xml.Linq.XDocument
replaceCursor bool
리턴 int
        public static int ApplyReplacements(TextDocument document, int cursor, XDocument replacements, bool replaceCursor = true)
        {
            var elements = replacements.Elements().First().Elements();

            document.BeginUpdate();

            var offsetChange = 0;
            foreach (var element in elements)
            {
                switch (element.Name.LocalName)
                {
                    case "cursor":
                        cursor = Convert.ToInt32(element.Value);
                        break;

                    case "replacement":
                        var offset = -1;
                        var replacementLength = -1;
                        var attributes = element.Attributes();

                        foreach (var attribute in attributes)
                        {
                            switch (attribute.Name.LocalName)
                            {
                                case "offset":
                                    offset = Convert.ToInt32(attribute.Value);
                                    break;

                                case "length":
                                    replacementLength = Convert.ToInt32(attribute.Value);
                                    break;
                            }
                        }

                        document.Replace(offsetChange + offset, replacementLength, element.Value);

                        offsetChange += element.Value.Length - replacementLength;
                        break;
                }
            }

            document.EndUpdate();

            return replaceCursor ? cursor : -1;
        }