Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

first version

  • Loading branch information...
commit 48cc03d67e1c9aaa7070b403dd469cef9b53d57a 0 parents
@svick authored
5 .gitignore
@@ -0,0 +1,5 @@
+*.suo
+*.user
+bin/
+obj/
+_ReSharper*
63 Demo app/Demo app.csproj
@@ -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>
27 Demo app/Program.cs
@@ -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));
+ }
+ }
+}
36 Demo app/Properties/AssemblyInfo.cs
@@ -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")]
42 XAML conversion.sln
@@ -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
36 XAML conversion/Properties/AssemblyInfo.cs
@@ -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")]
57 XAML conversion/XAML conversion.csproj
@@ -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>
71 XAML conversion/XamlConvertor.cs
@@ -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;
+ }
+ }
+}
305 XAML conversion/XamlParser.cs
@@ -0,0 +1,305 @@
+using System;
+using System.CodeDom;
+using System.Collections;
+using System.ComponentModel;
+using System.Globalization;
+using System.Text.RegularExpressions;
+using System.Windows.Data;
+using System.Windows.Markup;
+using System.Xml.Linq;
+
+namespace XamlConversion
+{
+ abstract class ParserBase
+ {
+ protected XamlConvertor.State State { get; set; }
+
+ protected ParserBase(XamlConvertor.State state)
+ {
+ State = state;
+ }
+
+ protected string CreateObject(Type type, string proposedName)
+ {
+ var variableName = State.GetVariableName(proposedName);
+ var variableDeclaration = new CodeVariableDeclarationStatement(
+ type.Name, variableName, new CodeObjectCreateExpression(type.Name));
+ State.AddStatement(variableDeclaration);
+ return variableName;
+ }
+
+ protected static Type GetTypeFromXName(XName xName)
+ {
+ string ns = xName.Namespace.NamespaceName;
+ if (string.IsNullOrEmpty(ns))
+ ns = "http://schemas.microsoft.com/netfx/2007/xaml/presentation";
+ return XamlTypeMapper.DefaultMapper.GetType(ns, xName.LocalName);
+ }
+
+ protected static Type GetPropertyType(string name, Type type)
+ {
+ return type.GetProperty(name).PropertyType;
+ }
+
+ protected CodeExpression ConvertTo(string value, Type type)
+ {
+ var valueExpression = new CodePrimitiveExpression(value);
+
+ var converter = TypeDescriptor.GetConverter(type);
+
+ if (type == typeof(string) || type == typeof(object))
+ return valueExpression;
+
+ if (type == typeof(double))
+ return new CodePrimitiveExpression(double.Parse(value, CultureInfo.InvariantCulture));
+
+ if (type == typeof(BindingBase))
+ {
+ var bindingParser = new BindingParser(State);
+ var bindingVariableName = bindingParser.Parse(value);
+ return new CodeVariableReferenceExpression(bindingVariableName);
+ }
+
+ // there is no conversion availabe, the generated code won't compile, but there is nothing we can do about that
+ if (converter == null)
+ return valueExpression;
+
+ var conversion = new CodeCastExpression(
+ type.Name,
+ new CodeMethodInvokeExpression(
+ new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("TypeDescriptor"), "GetConverter",
+ new CodeTypeOfExpression(type.Name)), "ConvertFromInvariantString",
+ new CodePrimitiveExpression(value)));
+
+ return conversion;
+ }
+
+ protected void SetProperty(string variableName, Type variableType, string propertyName, string value)
+ {
+ var left = new CodePropertyReferenceExpression(
+ new CodeVariableReferenceExpression(variableName), propertyName);
+ var right = ConvertTo(value, GetPropertyType(propertyName, variableType));
+ var assignment = new CodeAssignStatement(left, right);
+ State.AddStatement(assignment);
+ }
+ }
+
+ abstract class XamlParser : ParserBase
+ {
+ protected XamlParser(XamlConvertor.State state)
+ : base(state)
+ {}
+
+ public void Parse(XElement element)
+ {
+ ParseName(element.Name);
+
+ foreach (var attribute in element.Attributes())
+ ParseAttribute(attribute);
+
+ foreach (var childElement in element.Elements())
+ ParseElement(childElement);
+
+ ParseEnd();
+ }
+
+ protected abstract void ParseName(XName name);
+
+ protected abstract void ParseAttribute(XAttribute attribute);
+
+ protected abstract void ParseElement(XElement element);
+
+ protected abstract void ParseEnd();
+ }
+
+ class RootObjectParser : ObjectParser
+ {
+ public RootObjectParser(XamlConvertor.State state)
+ : base(state)
+ {}
+
+ protected override void ParseEnd()
+ {
+ var returnStatement = new CodeMethodReturnStatement(new CodeVariableReferenceExpression(VariableName));
+ State.AddStatement(returnStatement);
+ State.SetReturnType(Type);
+ }
+ }
+
+ class ObjectParser : XamlParser
+ {
+ public ObjectParser(XamlConvertor.State state)
+ : base(state)
+ {}
+
+ public string VariableName { get; protected set; }
+
+ public Type Type { get; protected set; }
+
+ protected override void ParseName(XName name)
+ {
+ Type = GetTypeFromXName(name);
+
+ VariableName = CreateObject(Type, name.LocalName);
+ }
+
+ protected override void ParseAttribute(XAttribute attribute)
+ {
+ var propertyName = attribute.Name.LocalName;
+ SetProperty(VariableName, Type, propertyName, attribute.Value);
+ }
+
+ protected override void ParseElement(XElement element)
+ {
+ // is it a property?
+ if (element.Name.LocalName.Contains("."))
+ {
+ var propertyParser = new PropertyParser(State, this);
+ propertyParser.Parse(element);
+ }
+ else
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ protected override void ParseEnd()
+ {}
+ }
+
+ class PropertyParser : XamlParser
+ {
+ public string Name { get; protected set; }
+
+ public Type Type { get; protected set; }
+
+ protected ObjectParser Parent { get; private set; }
+
+ private PropertyParser m_child;
+
+ public PropertyParser(XamlConvertor.State state, ObjectParser parent)
+ : base(state)
+ {
+ Parent = parent;
+ }
+
+ protected override void ParseName(XName name)
+ {
+ Name = name.LocalName.Split('.')[1];
+ Type = GetPropertyType(Name, Parent.Type);
+ // is it a collection?
+ if (typeof(IEnumerable).IsAssignableFrom(Type) && Type != typeof(string))
+ m_child = new PropertyCollectionParser(State, Parent);
+ else
+ m_child = new PropertyObjectParser(State, Parent);
+ m_child.ParseName(name);
+ }
+
+ protected override void ParseAttribute(XAttribute attribute)
+ {
+ throw new InvalidOperationException();
+ }
+
+ protected override void ParseElement(XElement element)
+ {
+ m_child.ParseElement(element);
+ }
+
+ protected override void ParseEnd()
+ {
+ m_child.ParseEnd();
+ }
+ }
+
+ class PropertyCollectionParser : PropertyParser
+ {
+ public PropertyCollectionParser(XamlConvertor.State state, ObjectParser parent)
+ : base(state, parent)
+ {}
+
+ protected override void ParseName(XName name)
+ {
+ Name = name.LocalName.Split('.')[1];
+ Type = GetPropertyType(Name, Parent.Type);
+ }
+
+ protected override void ParseElement(XElement element)
+ {
+ var objectParser = new ObjectParser(State);
+ objectParser.Parse(element);
+ var addExpression =
+ new CodeMethodInvokeExpression(
+ new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(Parent.VariableName), Name),
+ "Add", new CodeVariableReferenceExpression(objectParser.VariableName));
+ State.AddStatement(new CodeExpressionStatement(addExpression));
+ }
+
+ protected override void ParseEnd()
+ {}
+ }
+
+ class PropertyObjectParser : PropertyParser
+ {
+ private bool m_firstElement = true;
+
+ public PropertyObjectParser(XamlConvertor.State state, ObjectParser parent)
+ : base(state, parent)
+ {}
+
+ protected override void ParseName(XName name)
+ {
+ Name = name.LocalName.Split('.')[1];
+ Type = GetPropertyType(Name, Parent.Type);
+ }
+
+ protected override void ParseElement(XElement element)
+ {
+ if (!m_firstElement)
+ throw new InvalidOperationException();
+
+ var objectParser = new ObjectParser(State);
+ objectParser.Parse(element);
+
+ var left = new CodePropertyReferenceExpression(
+ new CodeVariableReferenceExpression(Parent.VariableName), Name);
+ var right = new CodeVariableReferenceExpression(objectParser.VariableName);
+ var assignment = new CodeAssignStatement(left, right);
+ State.AddStatement(assignment);
+ }
+
+ protected override void ParseEnd()
+ {}
+ }
+
+ class BindingParser : ParserBase
+ {
+ public BindingParser(XamlConvertor.State state)
+ : base(state)
+ {}
+
+ static readonly Regex BindingRegex = new Regex(@"\{([\w]+)(\s+\w+=\w+)*\}");
+
+ static readonly Regex BindingPropertyRegex = new Regex(@"(\w+)=(\w+)");
+
+ public string Parse(string text)
+ {
+ var match = BindingRegex.Match(text);
+
+ if (!match.Success)
+ throw new InvalidOperationException();
+
+ var type = GetTypeFromXName(match.Groups[1].Value);
+
+ string variableName = CreateObject(type, type.Name);
+ foreach (Capture capture in match.Groups[2].Captures)
+ {
+ var propertyMatch = BindingPropertyRegex.Match(capture.Value);
+ if (!propertyMatch.Success)
+ throw new InvalidOperationException();
+ SetProperty(variableName, type, propertyMatch.Groups[1].Value, propertyMatch.Groups[2].Value);
+ }
+
+ return variableName;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.