From a6bbed029c64d2d64b74eeb67e27a099abf70664 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Tue, 15 Nov 2016 20:39:48 +0100 Subject: [XamlC] TypedBindings, some tests, a compiler, ... (#489) --- Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs | 3 +- Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs | 3 +- .../MarkupExtensions/BindingExtension.cs | 14 ++++- Xamarin.Forms.Xaml/XamlCompilationAttribute.cs | 2 +- Xamarin.Forms.Xaml/XamlNode.cs | 5 +- Xamarin.Forms.Xaml/XamlParser.cs | 71 +++++++++++----------- Xamarin.Forms.Xaml/XmlName.cs | 1 + 7 files changed, 57 insertions(+), 42 deletions(-) (limited to 'Xamarin.Forms.Xaml') diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs index 36f5b7fd..154ba023 100644 --- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs +++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs @@ -19,7 +19,8 @@ namespace Xamarin.Forms.Xaml XmlName.xTypeArguments, XmlName.xArguments, XmlName.xFactoryMethod, - XmlName.xName + XmlName.xName, + XmlName.xDataType }; public ApplyPropertiesVisitor(HydratationContext context, bool stopOnResourceDictionary = false) diff --git a/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs b/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs index 36e8fc17..81893506 100644 --- a/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs +++ b/Xamarin.Forms.Xaml/ExpandMarkupsVisitor.cs @@ -17,7 +17,8 @@ namespace Xamarin.Forms.Xaml XmlName.xKey, XmlName.xTypeArguments, XmlName.xFactoryMethod, - XmlName.xName + XmlName.xName, + XmlName.xDataType }; Dictionary Values diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/BindingExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/BindingExtension.cs index 5b519e62..df82771d 100644 --- a/Xamarin.Forms.Xaml/MarkupExtensions/BindingExtension.cs +++ b/Xamarin.Forms.Xaml/MarkupExtensions/BindingExtension.cs @@ -1,4 +1,5 @@ using System; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Xaml { @@ -25,9 +26,20 @@ namespace Xamarin.Forms.Xaml public string UpdateSourceEventName { get; set; } + public TypedBindingBase TypedBinding { get; set; } + BindingBase IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) { - return new Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source) { UpdateSourceEventName = UpdateSourceEventName }; + if (TypedBinding == null) + return new Binding(Path, Mode, Converter, ConverterParameter, StringFormat, Source) { UpdateSourceEventName = UpdateSourceEventName }; + + TypedBinding.Mode = Mode; + TypedBinding.Converter = Converter; + TypedBinding.ConverterParameter = ConverterParameter; + TypedBinding.StringFormat = StringFormat; + TypedBinding.Source = Source; + TypedBinding.UpdateSourceEventName = UpdateSourceEventName; + return TypedBinding; } object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) diff --git a/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs b/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs index 76199039..79cc87bd 100644 --- a/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs +++ b/Xamarin.Forms.Xaml/XamlCompilationAttribute.cs @@ -21,7 +21,7 @@ namespace Xamarin.Forms.Xaml public XamlCompilationOptions XamlCompilationOptions { get; set; } } - internal static class XamlCExtensions + static class XamlCExtensions { public static bool IsCompiled(this Type type) { diff --git a/Xamarin.Forms.Xaml/XamlNode.cs b/Xamarin.Forms.Xaml/XamlNode.cs index a19e7d5c..752f3845 100644 --- a/Xamarin.Forms.Xaml/XamlNode.cs +++ b/Xamarin.Forms.Xaml/XamlNode.cs @@ -42,7 +42,7 @@ namespace Xamarin.Forms.Xaml } [DebuggerDisplay("{NamespaceUri}:{Name}")] - internal class XmlType + class XmlType { public XmlType(string namespaceUri, string name, IList typeArguments) { @@ -53,8 +53,7 @@ namespace Xamarin.Forms.Xaml public string NamespaceUri { get; } public string Name { get; } - public IList TypeArguments { get; private set; } - + public IList TypeArguments { get; } } internal abstract class BaseNode : IXmlLineInfo, INode diff --git a/Xamarin.Forms.Xaml/XamlParser.cs b/Xamarin.Forms.Xaml/XamlParser.cs index 60424754..f2ac3197 100644 --- a/Xamarin.Forms.Xaml/XamlParser.cs +++ b/Xamarin.Forms.Xaml/XamlParser.cs @@ -197,47 +197,48 @@ namespace Xamarin.Forms.Xaml if (reader.NamespaceURI == "http://schemas.microsoft.com/winfx/2006/xaml") { - switch (reader.Name) - { - case "x:Key": - propertyName = XmlName.xKey; - break; - case "x:Name": - propertyName = XmlName.xName; - break; - case "x:Class": - continue; - default: - Debug.WriteLine("Unhandled {0}", reader.Name); - continue; + switch (reader.Name) { + case "x:Key": + propertyName = XmlName.xKey; + break; + case "x:Name": + propertyName = XmlName.xName; + break; + case "x:Class": + continue; + default: + Debug.WriteLine("Unhandled attribute {0}", reader.Name); + continue; } } if (reader.NamespaceURI == "http://schemas.microsoft.com/winfx/2009/xaml") { - switch (reader.Name) - { - case "x:Key": - propertyName = XmlName.xKey; - break; - case "x:Name": - propertyName = XmlName.xName; - break; - case "x:TypeArguments": - propertyName = XmlName.xTypeArguments; - value = TypeArgumentsParser.ParseExpression((string)value, (IXmlNamespaceResolver)reader, (IXmlLineInfo)reader); - break; - case "x:Class": - continue; - case "x:FactoryMethod": - propertyName = XmlName.xFactoryMethod; - break; - case "x:Arguments": - propertyName = XmlName.xArguments; + switch (reader.Name) { + case "x:Key": + propertyName = XmlName.xKey; + break; + case "x:Name": + propertyName = XmlName.xName; break; - default: - Debug.WriteLine("Unhandled {0}", reader.Name); - continue; + case "x:TypeArguments": + propertyName = XmlName.xTypeArguments; + value = TypeArgumentsParser.ParseExpression((string)value, (IXmlNamespaceResolver)reader, (IXmlLineInfo)reader); + break; + case "x:DataType": + propertyName = XmlName.xDataType; + break; + case "x:Class": + continue; + case "x:FactoryMethod": + propertyName = XmlName.xFactoryMethod; + break; + case "x:Arguments": + propertyName = XmlName.xArguments; + break; + default: + Debug.WriteLine("Unhandled attribute {0}", reader.Name); + continue; } } diff --git a/Xamarin.Forms.Xaml/XmlName.cs b/Xamarin.Forms.Xaml/XmlName.cs index 09cf3bca..92e1fc04 100644 --- a/Xamarin.Forms.Xaml/XmlName.cs +++ b/Xamarin.Forms.Xaml/XmlName.cs @@ -11,6 +11,7 @@ namespace Xamarin.Forms.Xaml public static readonly XmlName xTypeArguments = new XmlName("x", "TypeArguments"); public static readonly XmlName xArguments = new XmlName("x", "Arguments"); public static readonly XmlName xFactoryMethod = new XmlName("x", "xFactoryMethod"); + public static readonly XmlName xDataType = new XmlName("x", "DataType"); public static readonly XmlName Empty = new XmlName(); public string NamespaceURI { get; } -- cgit v1.2.3