469,951 Members | 2,336 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

Porting from VS2003 to VS2005: Code reformatting

No reply on my previous query, so I'll post this again. I've done a
bit more research in the interim.

I'm trying to find an easy way to port code from the older VS2003
format to the format used in VS2005. VS2005 uses partial classes to
split off the compiler-generated sections of forms. It keeps the
editable files uncluttered.

I generated very simple projects with VS2003 and with VS2005 to
compare the output. Following are standout differences:

VS2003's Form1.cs gets split into three modules:

Form1.cs (the new one) has only the constructor and event response
functions. Form1 class is declared partial.

Form1.designer.cs also has a partial Form1 class.
This file gets the Dispose() and InitializeComponent()
functions, and all the dialog objects.
For some reason, the 'components' object derives from
'IContainer' in VS2005 rather than 'Containter'
(Anyone know about this?)
The InitializeComponent() function replaces the old
'AutoScaleBaseSize =' to two new lines:
'AutoScaleDimensions = ...' and
'AutoScaleMode = ...'

Program.cs gets the Main() function, now in its own static class.
VS2005's Main() adds a call to EnableVisualStyles()

----------------------

Those appear to be the main differences. I'm not sure if the compiler
flags are changed, but the code changes seem like they could be done
with a reformatting program. Given the vast body of VS2003 code
with big clumsy dialogs, it would make sense to have a reformatter.

So...does it exist?

Nov 17 '05 #1
2 2608
DG,

Unfortunately, it does not exist. What you could do is create an
instance of the CSharpCodeProvider class in the Microsoft.CSharp namespace.

Once you have that, you can call the Parse method to parse the code into
an object which has the contents of the old code (after all, it should keep
working).

Then, you can create a new file, and take the elements of the code from
the old code file, and place them in the new code file.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"-DG-" <-D**@nospam.com> wrote in message
news:uk********************************@4ax.com...
No reply on my previous query, so I'll post this again. I've done a
bit more research in the interim.

I'm trying to find an easy way to port code from the older VS2003
format to the format used in VS2005. VS2005 uses partial classes to
split off the compiler-generated sections of forms. It keeps the
editable files uncluttered.

I generated very simple projects with VS2003 and with VS2005 to
compare the output. Following are standout differences:

VS2003's Form1.cs gets split into three modules:

Form1.cs (the new one) has only the constructor and event response
functions. Form1 class is declared partial.

Form1.designer.cs also has a partial Form1 class.
This file gets the Dispose() and InitializeComponent()
functions, and all the dialog objects.
For some reason, the 'components' object derives from
'IContainer' in VS2005 rather than 'Containter'
(Anyone know about this?)
The InitializeComponent() function replaces the old
'AutoScaleBaseSize =' to two new lines:
'AutoScaleDimensions = ...' and
'AutoScaleMode = ...'

Program.cs gets the Main() function, now in its own static class.
VS2005's Main() adds a call to EnableVisualStyles()

----------------------

Those appear to be the main differences. I'm not sure if the compiler
flags are changed, but the code changes seem like they could be done
with a reformatting program. Given the vast body of VS2003 code
with big clumsy dialogs, it would make sense to have a reformatter.

So...does it exist?

Nov 17 '05 #2
On Mon, 31 Oct 2005 11:00:12 -0500, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard.caspershouse.com> wrote:
Unfortunately, it does not exist. What you could do is create an
instance of the CSharpCodeProvider class in the Microsoft.CSharp namespace.

Once you have that, you can call the Parse method to parse the code into
an object which has the contents of the old code (after all, it should keep
working).

Then, you can create a new file, and take the elements of the code from
the old code file, and place them in the new code file.


Well, that's an interesting approach. I hadn't noticed
CSharpCodeProvider. I'll take a closer look.

In the interim, after comparing code listings for several projects, I
sort of got the hang of the major differences.

I've been starting by generating a new VS2005 project with one button
(to easily find position of where the controls are added in). That
way, I'm sure that the compile and link switches are set correctly and
the underlying structure is correct.

Then I incrementally copy code from the VS2003 project, splitting into
the form1.cs and form1.designer.cs as appropriate. (Nice to split off
the compiler-gen'd stuff...Partial classes are handy!)

I'm still not sure of the reasoning behind some of the changes, like
VS2005's use of floats in:
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
intstead of the older integer version.

From what i've seen, the format changes are pretty coherent and
predictable, so a translator program would be possible. Someone
should get right on that <g>. Maybe use the parser that you
mentioned.


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Samuel | last post: by
6 posts views Thread by =?Utf-8?B?RGlwZXNoX1NoYXJtYQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.