110 likes | 257 Vues
Converting the Code. What the code consists of ?. Using declarations Namespace declaration Class declaration Variable declarations Method declarations Return Type Parameters Method body Operations (Method calls, Variable declarations).
E N D
What the code consists of ? • Using declarations • Namespace declaration • Class declaration • Variable declarations • Method declarations • Return Type • Parameters • Method body • Operations (Method calls, Variable declarations)
Changes in the .NET framework? .NET 4.0 vs .NET 4.5 (Metro) • Why we need to convert the code? • Location of classes have changed • E.g. System.Windows.Forms.TextBox is now in Windows.UI.Xaml.Controls.TextBox. • Methods have changed • E.g. System.IO.File.ReadAllText()has been replaced with Windows.Storage.PathIO.ReadTextAsync()
Changes in the .NET framework? (cont’d) • Some Controls are removed • No DataGridView • No Multiple Document Interface • MessageBox have changed • Try to provide our own controls to fullfil these needs
Changes in the .NET framework?(cont’d) • More emphasis for asynchronous calls • New async, await keywords • New methods in classes which run asynchronously • e.g. System.IO.Stream.ReadAsync()
Steps in code conversion • Convert the using declarations • Change old using declarations to new ones • Add additional required using declarations • Convert class declaration • Convert method declarations • Data type changes • Event handler special cases • Convert Operations • Method calls • Assignment operations • Etc.
Steps in code conversion Convert method declarations Convert operations Convert class declaration .NET 4.5 (Metro style) .NET 4.0 Convert the using declarations
Overview of the conversion process Input C# code file (.cs) Output C# code file (.xaml.cs) Extract Information about classes, methods, etc. in the files Convert using declarations Convert method declarations Convert operations Control mapping, Data type mapping, Method invocation mappings Using declaration conversion rules Data type mapping
How the conversion is done • The basic process in which using declarations, method declarations, operations etc. are converted from .NET 4.0 to .NET 4.5 is the same. But each need special handlings as well. • Following is an example of one such scenario
Conversion of a simple operation (method call) 1) Use Roslyn APIs to break down the code Ex. Basic structure of code line MessageBox.Show(count.ToString(), "Message"); • Build up information of what the user written code mean • MessageBox, Show, count, ToString are knows as identifier tokens • Identify that MessageBox.Show together is a Method call
Conversion of a simple operation 2) Check if this method call need to be converted. If so get what the new call is. (Known as a conversion rule) • Generated the new Method call as TransMessageBox.Show(count.ToString(), "Message"); • Replace the old method call in the code with the newly converted method call System.Windows.Forms.MessageBox.Show(Old) => TranscendersWrapper.TransMessageBox.Show(New) MethodSignature.xml