Author Topic: Code generation?  (Read 3593 times)

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
Code generation?
« on: June 13, 2007, 10:02:14 am »
Let's say I have the following C# class with just a ctor/method:

Code: [Select]
public class MyClass
{
      public MyClass (int param1, Type param2)
      {
      }
}

I would like from that point to generate 3 code snippets from a method's parameter information. E.g set the cursor on one of the parameters, bring the right click menu and use some added items from there with the functionality as follows.

Code: [Select]
public class MyClass
{
      // First code I want to generate, just after the class signature - "Generate private field"
      //
      private int _param1;
      private Type _param2;

      public MyClass (int param1, Type param2)
      {
            // Second code snippet - "Generate verification and assignment"
            //
            if (param2 == null)
                  throw new ArgumentNullException ("param2");
            _param1 = param;
            _param2 = param2;
      }

      // Third code snippet after the method's body - "Generate Property"
      //
      public int Param1 {
            get { return _param1; }
            set { _param1 = value; }
      }

      public Type Param2 {
            get { return _param2; }
            set { _param2 = value; }
      }
}

All good, but I don't have a clue how to do that. I read the Slick-C manual but that was just an overview of the language and some UI design features of SlickEdit. Is there a tutorial and examples on code generation and parsing/using tag information?

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: Code generation?
« Reply #1 on: June 19, 2007, 07:46:46 pm »
What version of SE are you using? In 12.0.1 we introduced a _cs_generate_debug() method in quickrefactor.e. That's simply a modification of the previous _c_generate_debug(). So you could refer to any of the ??_generate_debug methods in a previous version.
There aren't a lot of deep tutorial docs on using the tag browse info, but these methods quickrefactor.e are good place to start looking for working examples.