Home > Code Generation > Code Generation – Create Descendant and Create Descendant (with virtual overrides)

Code Generation – Create Descendant and Create Descendant (with virtual overrides)

June 30th, 2011

The Create Descendant code provider shipped in CodeRush generates a descendant class for the active class, providing overrides for abstract members, if any. The second version of the code provider named Create Descendant (with virtual overrides), in addition to the Create Descendant, adds overrides for virtual members into a descendant class.

Applying the Create Descendant for the following abstract class:

public abstract class Logger
{
  public abstract void GetMessage(int index);
  public abstract void SendMessage(string msg);
}

Will generate the following descendant declaration:

public class LoggerDescendant : Logger
{
  public LoggerDescendant()
  {

  }
  public override void GetMessage(int index)
  {
    throw new NotImplementedException();
  }
  public override void SendMessage(string msg)
  {
    throw new NotImplementedException();
  }
}

If a class contains virtual members you can choose whether they should be overridden by applying the corresponding provider. Having the following class:

public class Calculator
{
  public virtual void Add() { }
  public virtual void Sub() { }
  public virtual void Mul() { }
  public virtual void Div() { }
}

Applying the Create Descendant (with virtual overrides) will result in generating the following class:

public class CalculatorDescendant : Calculator
{
  public CalculatorDescendant()
  {

  }
  public override void Add()
  {
    base.Add();
  }
  public override void Sub()
  {
    base.Sub();
  }
  public override void Mul()
  {
    base.Mul();
  }
  public override void Div()
  {
    base.Div();
  }
}

Both code providers add a default public parameterless constructor for the new class, and drop a marker at the starting source position. The new class is placed above the current class in the same source file.

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

Similar Posts:

  1. June 4th, 2012 at 21:32 | #1

    Fatal error: Uncaught Error: Call to undefined function eregi_replace() in H:\root\home\megazoid-001\www\skorkincom\wp-content\plugins\bbcomments\BBComments.php:41 Stack trace: #0 H:\root\home\megazoid-001\www\skorkincom\wp-includes\class-wp-hook.php(289): render_comment() #1 H:\root\home\megazoid-001\www\skorkincom\wp-includes\plugin.php(212): WP_Hook->apply_filters() #2 H:\root\home\megazoid-001\www\skorkincom\wp-includes\comment-template.php(1028): apply_filters() #3 H:\root\home\megazoid-001\www\skorkincom\wp-content\themes\inove\functions.php(1163): comment_text() #4 H:\root\home\megazoid-001\www\skorkincom\wp-includes\class-walker-comment.php(179): custom_comments() #5 H:\root\home\megazoid-001\www\skorkincom\wp-includes\class-wp-walker.php(144): Walker_Comment->start_el() #6 H:\root\home\megazoid-001\www\skorkincom\wp-includes\class-walker-comment.php(139): Walker->display_element() #7 H:\root\home\megazoid-001\www\skorkincom\wp-includes\class-wp-walker.php(332): Walker_Comment->display_element() #8 H:\root\home\me in H:\root\home\megazoid-001\www\skorkincom\wp-content\plugins\bbcomments\BBComments.php on line 41
    WordPress › Error

    There has been a critical error on this website.

    Learn more about debugging in WordPress.