예제 #1
0
        void CreateMethodEditPoint()
        {
            var startPoint = (TextPoint)codeFunction.GetStartPoint();

            endPoint  = (TextPoint)codeFunction.GetEndPoint();
            editPoint = (EditPoint)startPoint.CreateEditPoint();
        }
예제 #2
0
        /// <summary>
        /// Add function to the specified class with the given body.
        /// </summary>
        /// <param name="p_securedClass"></param>
        /// <param name="p_functionName"></param>
        /// <param name="p_functionBody"></param>
        private static void AddFunction(CodeClass2 p_securedClass, string p_functionName, string p_functionBody)
        {
            // Add a method with a parameter to the class.
            CodeFunction2 testFunction = (CodeFunction2)p_securedClass.AddFunction(p_functionName, vsCMFunction.vsCMFunctionFunction, "void", -1, vsCMAccess.vsCMAccessPublic, null);

            testFunction.AddAttribute("TestMethod", string.Empty);

            var startPoint = testFunction.GetStartPoint(vsCMPart.vsCMPartBody);
            var endPoint   = testFunction.GetEndPoint(vsCMPart.vsCMPartBody);
            var editPoint  = startPoint.CreateEditPoint() as EditPoint2;

            // Clear the default generated body
            editPoint.Delete(endPoint);
            editPoint.Indent(null, 1);

            // Write the body of the function
            editPoint.Insert(p_functionBody);
            editPoint.InsertNewLine();

            endPoint = testFunction.GetEndPoint(vsCMPart.vsCMPartBody);
            editPoint.SmartFormat(endPoint);
        }
예제 #3
0
        /// <summary>
        /// Returns inner text of the function (no header, no braces)
        /// </summary>
        public static string GetText(this CodeFunction2 codeFunction)
        {
            if (codeFunction == null)
            {
                throw new ArgumentNullException("codeFunction");
            }

            TextPoint startPoint = codeFunction.GetStartPoint(vsCMPart.vsCMPartBody);
            TextPoint endPoint   = codeFunction.GetEndPoint(vsCMPart.vsCMPartBody);

            EditPoint ep = startPoint.CreateEditPoint();

            if (ep == null)
            {
                return(null);
            }
            else
            {
                return(ep.GetText(endPoint));
            }
        }