Welcome Guest Search | Active Topics | Members | Log In | Register

Some handy methods Options · View
derek
Posted: Thursday, April 24, 2008 4:52:11 AM
Rank: Advanced Member
Groups: Member

Joined: 4/24/2008
Posts: 6
Points: 18
Location: Scotland
Hi,

It would good if there were a collection of some methods, maybe macros would be better, build in to AutoCode to let you do common things. Some examples might be AddUsing, to add a 'using namespace' statement at the top of the file, ImplementInterface, to have the containing class implement an interface, AddMethodParameters, to add a parameter to an existing method.

These are very common things that people might want to do so instead of everyone writing their own implementations then build them into AutoCode.
Alvaro
Posted: Thursday, April 24, 2008 8:31:44 PM
Rank: Administration
Groups: Administration

Joined: 3/16/2008
Posts: 22
Points: 72
Location: Spain
Hi Derek,

I agree there should be some helpers to be used inside AutoCode, and that will be one of the new features of next version.

By now, there are still some ways to do what you say. For instance:

AddUsing

The following Code inserts a using statement at the beginning of the document.

Code:
        <Code id="AddUsing" codeElement="Document" codePoint="StartOfDocument" >
          <![CDATA[using AnyNamespace;
]]>
        </Code>


AddParameter

A parameter can be inserted in a function overriding the Render method, it is, using the Render tag as follows:

Code:
      <Render>
        CodeFunction cf = (CodeFunction) Selection.ActivePoint.get_CodeElement(vsCMElement.vsCMElementFunction);
        cf.AddParameter("myParam", vsCMTypeRef.vsCMTypeRefInt, -1);
      </Render>


The argument -1 means at the end of the argument list. You can change it for the ordinal position.

Implementing an Interface

Implementing an Interface can be done positioning the cursor at the end of the class name, inserting
the <InterfaceName> text and executing the “Edit.ImplementInterfaceStubsImplicitly” command.

Code:
      <Execute>
        // Get the start of class position
        CodeElement ce = GetCodeElement(CodeElementTypes.Class);
        TextPoint cp = GetCodePoint(ce, CodePositions.StartOfElement);
        // Move Selection to that point
        Selection.MoveToPoint(cp, false);
        // Position to the end of the class name
        Selection.EndOfLine(false);
        // Write the interface name
        Selection.Text = " : IDisposable";

        // Let VS IDE implement the interface
        DTE.ExecuteCommand("Edit.ImplementInterfaceStubsImplicitly", "");
     </Execute>


Hope this could help,

Alvaro


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008