Home > Code Generation > Code Generation – Create Ancestor

Code Generation – Create Ancestor

June 29th, 2011

The Create Ancestor code provider generates a new base class declaration for the active class. The generated base class will be declared above the active class and the active class becomes a descendant of the new base class. The new base class has the same visibility as the active class and contains the default public parameterless constructor. All identifiers and references of the base class are linked together for easy renaming.

For example, applying the Create Ancestor for the following class:

public class Logger
  public Logger() { }

Will result in the following result:

public class LoggerBase
  public LoggerBase()

public class Logger : LoggerBase
  public Logger() { }

Note that the code provider won’t be available when the active class already descends from another base class.

Products: CodeRush Pro
Versions: 11.1 and up
VS IDEs: any
Updated: Jun/30/2011
ID: C108

Similar Posts:

  1. Neal
    June 30th, 2011 at 17:17 | #1

    Why isn’t the base class marked abstract?

  2. July 1st, 2011 at 04:08 | #2

    Not sure if base classes should always be marked as abstract, should they? Probably, we could make an additional code provider that will create a descendant marked abstract.

  3. June 4th, 2012 at 21:08 | #3

    Hi Alex. I have translated your nice article and published on the following URL:

  4. June 4th, 2012 at 22:34 | #4

    Hideaki, thank you very much!