Dev2.Intellisense.Provider.FileSystemIntellisenseProvider.PerformResultInsertion C# (CSharp) Method

PerformResultInsertion() public method

public PerformResultInsertion ( string input, IntellisenseProviderContext context ) : string
input string
context Dev2.Studio.Core.Interfaces.IntellisenseProviderContext
return string
        public string PerformResultInsertion(string input, IntellisenseProviderContext context)
        {
            VerifyArgument.IsNotNull("Context",context);
           
            string inputText = context.InputText ?? string.Empty;
            int caretPosition = context.CaretPosition;  

            if (caretPosition < 0 || caretPosition>inputText.Length)
                return string.Empty;

            var regions = inputText.Split(' '); // we can safely do this because the default provider handles the language features

            var sum = 0;
            int items = 0;
            var regionsText = regions.Select(a => new { a, a.Length }).TakeWhile(a =>
            {
                sum = sum + a.Length;
                items++;
                return sum <= caretPosition || items==1;
            }).Select(a => a.a).ToList();
            regionsText[regionsText.Count - 1] = input;// set caret region to replacement text

            var prefix = regionsText.Aggregate("", (a, b) => a + " " + b).TrimStart(' '); // fold back together
            context.CaretPositionOnPopup = prefix.Length;
            context.CaretPosition = prefix.Length;
            int i = 0;
            var inner = regions.SkipWhile(a =>
                {
                    i = i + 1;
                    return i < regionsText.Count + 1;
                }).Aggregate("", (a, b) => a + " " + b);
            return (prefix + inner).TrimEnd();

        }

Usage Example

        public void FileSystemIntellisenseProvider_ExecuteInsertion(int caretPosition, string inputText, string inserted, string expected)
        {
            //------------Setup for test--------------------------
            var fileSystemIntellisenseProvider = new FileSystemIntellisenseProvider();

            //------------Execute Test---------------------------
            var context = new IntellisenseProviderContext
            {
                CaretPosition = caretPosition,
                InputText = inputText,
                IsInCalculateMode = false,
                DesiredResultSet = IntellisenseDesiredResultSet.ClosestMatch
            };

               var resp =  fileSystemIntellisenseProvider.PerformResultInsertion(inserted, context);
            //------------Assert Results-------------------------
            Assert.AreEqual(resp, expected);
        }
All Usage Examples Of Dev2.Intellisense.Provider.FileSystemIntellisenseProvider::PerformResultInsertion