Example #1
0
        public static void doCreateXMLDocumentForFunction(EnvDTE.CodeFunction func)
        {
            // probably should use StringBuilder here for better performance/memory use
            // but am not as readability is main purpose of example
            string xmlComments = "";

            xmlComments +=
                "\t\t/// <summary> " + func.Name + "()";

            switch (func.FunctionKind)
            {
            case vsCMFunction.vsCMFunctionConstructor:
                xmlComments += " constructor"; break;

            case vsCMFunction.vsCMFunctionDestructor:
                xmlComments += " destructor"; break;

            default: break;
            }

            if (func.Parameters.Count <= 0)
            {
                xmlComments += ".  No parameters";
            }
            xmlComments += ". </summary> \n";

            foreach (CodeParameter param in func.Parameters)
            {
                xmlComments +=
                    "\t\t/// <param name=\"" + param.Name + "\"> type: " +
                    param.Type.AsString + "</param> \n";
            }
            xmlComments +=
                "\t\t/// <returns> " + func.Type.AsString + "</returns>\n";


            Debug.WriteLine(xmlComments);

            if (func.DocComment.Length <= 1)
            {
                // this does not work: func.DocComment = xmlComments;
                // editing does work
                Debug.WriteLine("writing XML comments to source file...");
                EnvDTE.TextPoint tp = func.GetStartPoint(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes);
                EnvDTE.EditPoint ep = tp.CreateEditPoint();
                ep.StartOfLine();
                ep.Insert(xmlComments);
            }
            else
            {
                Debug.WriteLine("XML comments already present in source file:");
                Debug.WriteLine(func.DocComment);
                Debug.WriteLine("-- end doc comment --");
            }
        }