summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-01 22:40:20 +0100
committerGitHub <noreply@github.com>2016-12-01 22:40:20 +0100
commit3ff3487d4fa5edb7ba3dcd7b6db0e6b58b03809c (patch)
treec522f65d25b5c1a6d6cd94e25245f35919f3c284 /Xamarin.Forms.Xaml
parent1ff0db9c6f4ba1167e6b2620066f83088f23c5bf (diff)
downloadxamarin-forms-3ff3487d4fa5edb7ba3dcd7b6db0e6b58b03809c.tar.gz
xamarin-forms-3ff3487d4fa5edb7ba3dcd7b6db0e6b58b03809c.tar.bz2
xamarin-forms-3ff3487d4fa5edb7ba3dcd7b6db0e6b58b03809c.zip
[XamlC] provide backward compat for ProvideValueTarget without Target… (#583)
* [XamlC] provide backward compat for ProvideValueTarget without TargetProperty * docs
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs23
-rw-r--r--Xamarin.Forms.Xaml/XamlServiceProvider.cs5
2 files changed, 18 insertions, 10 deletions
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
index a7f59be8..dc80ade2 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -12,21 +12,19 @@ namespace Xamarin.Forms.Xaml
{
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
- if (Key == null)
- {
- var lineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ if (Key == null) {
+ var lineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
var lineInfo = (lineInfoProvider != null) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();
throw new XamlParseException("you must specify a key in {StaticResource}", lineInfo);
}
- var valueProvider = serviceProvider.GetService(typeof (IProvideValueTarget)) as IProvideParentValues;
+ var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideParentValues;
if (valueProvider == null)
throw new ArgumentException();
- var xmlLineInfoProvider = serviceProvider.GetService(typeof (IXmlLineInfoProvider)) as IXmlLineInfoProvider;
+ var xmlLineInfoProvider = serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider;
var xmlLineInfo = xmlLineInfoProvider != null ? xmlLineInfoProvider.XmlLineInfo : null;
object resource = null;
- foreach (var p in valueProvider.ParentObjects)
- {
+ foreach (var p in valueProvider.ParentObjects) {
var ve = p as VisualElement;
var resDict = ve?.Resources ?? p as ResourceDictionary;
if (resDict == null)
@@ -36,7 +34,7 @@ namespace Xamarin.Forms.Xaml
}
if (resource == null && Application.Current != null && Application.Current.Resources != null &&
Application.Current.Resources.ContainsKey(Key))
- resource = Application.Current.Resources [Key];
+ resource = Application.Current.Resources[Key];
if (resource == null)
throw new XamlParseException($"StaticResource not found for key {Key}", xmlLineInfo);
@@ -44,12 +42,17 @@ namespace Xamarin.Forms.Xaml
var bp = valueProvider.TargetProperty as BindableProperty;
var pi = valueProvider.TargetProperty as PropertyInfo;
var propertyType = bp?.ReturnType ?? pi?.PropertyType;
- if (propertyType == null)
+ if (propertyType == null) {
+ if (resource.GetType().GetTypeInfo().IsGenericType && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>) || resource.GetType().GetGenericTypeDefinition() == typeof(OnIdiom<>))) {
+ // This is only there to support our backward compat story with pre 2.3.3 compiled Xaml project who was not providing TargetProperty
+ var method = resource.GetType().GetRuntimeMethod("op_Implicit", new[] { resource.GetType() });
+ resource = method.Invoke(resource, new[] { resource });
+ }
return resource;
+ }
if (propertyType.IsAssignableFrom(resource.GetType()))
return resource;
var implicit_op = resource.GetType().GetRuntimeMethod("op_Implicit", new [] { resource.GetType() });
- //This will invoke the op_implicit on OnPlatform<>
if (implicit_op != null && propertyType.IsAssignableFrom(implicit_op.ReturnType))
return implicit_op.Invoke(resource, new [] { resource });
diff --git a/Xamarin.Forms.Xaml/XamlServiceProvider.cs b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
index 19dd96f5..5052a180 100644
--- a/Xamarin.Forms.Xaml/XamlServiceProvider.cs
+++ b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
@@ -137,6 +137,11 @@ namespace Xamarin.Forms.Xaml.Internals
readonly object[] objectAndParents;
readonly object targetProperty;
+ [Obsolete("TargetProperty is now supported, use it")]
+ public SimpleValueTargetProvider(object[] objectAndParents) : this (objectAndParents, null)
+ {
+ }
+
public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty)
{
if (objectAndParents == null)