3

The old code, as we know, is dangerous because both GUI layout and business logic are mixed into one. Separating the two can be a tedious and an error-prone task. Is there a tool that can do this for me?

Thanks.

EDIT: The pretty obvious way of keeping the UI and the logic separate is through introduction of a partial class. I hope that clarifies the question. I suppose I am simply trying to go from 1.1 to 2.0 way of doing things. Simply opening and saving the old design in VS2008 does not do what I want.

Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147

3 Answers3

3

No tool, but easily accomplished with cut-and-paste text editing. Add a new form to your project. In the Solution Explorer, open the node next to the form and double-click the Designer.cs file. Cut and paste the InitializeComponent() method from your old form to that file. Cut and paste the rest of your code. Remove the old form, change the class name of the new one.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
2

There is no "standard", but lots of standard like ways people separate logic from UI. It forces you to design a particular way. So its a bit impossible to automatically redesign your software.

The best you have is refactoring tools, check out something like Resharper, makes it a bit safer to make some transformations.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • 1
    +1, ReSharper 5 has an action "Move declaration(s) to another type part", which moves selected declaration(s) to another partial class. – Jens Granlund Apr 28 '10 at 23:39
1

No. Sry to say but there is no such tool, that is still manual work. If you're looking into doing it anyway I would suggest looking into WPF development, since the separation is much easier to realize there.

ntziolis
  • 10,091
  • 1
  • 34
  • 50
  • Why is the separation any easier with WPF? I've never had any problems keeping separation of concerns with WinForms or WebForms. "Just Say No" to business logic on the page / form. – John Saunders Apr 28 '10 at 22:42
  • For me that mainly relates to the easier and more powerful binding. Yes, a lot of the binding available today in WPF was possible with WinForms but it was way more complicated to setup and it clocked up the codebehind files. But its a personal thing I guess since I consider proper binding and included validation part of the business logic. – ntziolis Apr 29 '10 at 01:04