O'Reilly logo

Extreme Programming Adventures in C# by Ron Jeffries

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. Don’t Try This at Home

Concern over potential code duplication in menus led me to do a little research. That led me to a really cool feature. I think I went down a rat hole—what do you think?

The Idle Brain Is the Devil’s Playground

In looking at the menu method from last time, I can foresee duplication of code. The method looked like this:

void MenuInsertSection(object obj, EventArgs ea) {
  model.SetLines(textbox.Lines);
  model.SelectionStart = textbox.SelectionStart;
  model.InsertSectionTags();
  PutText(textbox, model.LinesArray(), model.SelectionStart);
}

Now I foresee that lots of insertion methods are coming; I’ve seen the stories. There will be one to insert plain code like the method here, one for those precis things at the top of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required