Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48cc03d
Showing
9 changed files
with
642 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.suo | ||
*.user | ||
bin/ | ||
obj/ | ||
_ReSharper* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F905D677-17DD-4759-A194-7B7482343CEA}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Demo_app</RootNamespace> | ||
<AssemblyName>Demo app</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\XAML conversion\XAML conversion.csproj"> | ||
<Project>{CE11B1F5-1289-4197-B1E9-816D9B040785}</Project> | ||
<Name>XAML conversion</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using XamlConversion; | ||
|
||
namespace Demo_app | ||
{ | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
string xaml = @" | ||
<ListView Name=""listView"" Margin=""0,0,0,164""> | ||
<ListView.View> | ||
<GridView> | ||
<GridView.Columns> | ||
<GridViewColumn Header=""Devise"" DisplayMemberBinding=""{Binding Path=devise}"" Width=""80"" /> | ||
<GridViewColumn Header=""Libelle"" DisplayMemberBinding=""{Binding Path=label}"" Width=""120"" /> | ||
<GridViewColumn Header=""Unite"" DisplayMemberBinding=""{Binding Path=unite}"" Width=""80"" /> | ||
<GridViewColumn Header=""Achat"" DisplayMemberBinding=""{Binding Path=achatBanque}"" Width=""80"" /> | ||
<GridViewColumn Header=""Vente"" DisplayMemberBinding=""{Binding Path=venteBanque}"" Width=""80"" /> | ||
</GridView.Columns> | ||
</GridView> | ||
</ListView.View> | ||
</ListView>"; | ||
Console.WriteLine(new XamlConvertor().ConvertToString(xaml)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Demo app")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("Demo app")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("0c54bee4-24ef-407f-abbb-57e31da0e2f7")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XAML conversion", "XAML conversion\XAML conversion.csproj", "{CE11B1F5-1289-4197-B1E9-816D9B040785}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo app", "Demo app\Demo app.csproj", "{F905D677-17DD-4759-A194-7B7482343CEA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||
{CE11B1F5-1289-4197-B1E9-816D9B040785}.Release|x86.ActiveCfg = Release|Any CPU | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Debug|x86.ActiveCfg = Debug|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Debug|x86.Build.0 = Debug|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Release|Any CPU.ActiveCfg = Release|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Release|x86.ActiveCfg = Release|x86 | ||
{F905D677-17DD-4759-A194-7B7482343CEA}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("XAML conversion")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("XAML conversion")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("6cf06685-d9c5-4a64-9fe5-a61b7d5a0aeb")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{CE11B1F5-1289-4197-B1E9-816D9B040785}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>XamlConversion</RootNamespace> | ||
<AssemblyName>XAML conversion</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="PresentationFramework" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xaml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="XamlConvertor.cs" /> | ||
<Compile Include="XamlParser.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.CodeDom; | ||
using System.CodeDom.Compiler; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Xml.Linq; | ||
using Microsoft.CSharp; | ||
|
||
namespace XamlConversion | ||
{ | ||
public class XamlConvertor | ||
{ | ||
internal class State | ||
{ | ||
private readonly Dictionary<string, int> m_variables = new Dictionary<string, int>(); | ||
|
||
public CodeMemberMethod Method { get; set; } | ||
|
||
public State() | ||
{ | ||
Method = new CodeMemberMethod { Name = "Get" }; | ||
} | ||
|
||
public void AddStatement(CodeStatement statement) | ||
{ | ||
Method.Statements.Add(statement); | ||
} | ||
|
||
public void SetReturnType(Type returnType) | ||
{ | ||
Method.ReturnType = new CodeTypeReference(returnType.Name); | ||
} | ||
|
||
public string GetVariableName(string originalName) | ||
{ | ||
originalName = originalName.Substring(0, 1).ToLower() + originalName.Substring(1); | ||
if (m_variables.ContainsKey(originalName)) | ||
{ | ||
var number = ++m_variables[originalName]; | ||
return originalName + number; | ||
} | ||
else | ||
{ | ||
m_variables.Add(originalName, 1); | ||
return originalName; | ||
} | ||
} | ||
} | ||
|
||
|
||
public string ConvertToString(string xamlCode) | ||
{ | ||
var dom = ConvertToDom(xamlCode); | ||
var compiler = new CSharpCodeProvider(); | ||
var stringWriter = new StringWriter(); | ||
compiler.GenerateCodeFromMember(dom, stringWriter, new CodeGeneratorOptions{BracingStyle = "C"}); | ||
return stringWriter.ToString(); | ||
} | ||
|
||
public CodeMemberMethod ConvertToDom(string xamlCode) | ||
{ | ||
var state = new State(); | ||
|
||
XElement root = XElement.Parse(xamlCode); | ||
|
||
new RootObjectParser(state).Parse(root); | ||
|
||
return state.Method; | ||
} | ||
} | ||
} |
Oops, something went wrong.