summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-10-18 07:15:11 (GMT)
committerStephane Delcroix <stephane@delcroix.org>2017-10-18 07:17:24 (GMT)
commit59d9171a51e5554649720702e4baab603df5601a (patch)
treefdffded4f6f896fbc364c83f3e623c3121c3545b /Xamarin.Forms.Xaml
parent2b55a39cd940bc60095bde966d3475abe6c47d64 (diff)
downloadxamarin-forms-59d9171a51e5554649720702e4baab603df5601a.zip
xamarin-forms-59d9171a51e5554649720702e4baab603df5601a.tar.gz
xamarin-forms-59d9171a51e5554649720702e4baab603df5601a.tar.bz2
[Xaml] Chain op_implicit for OnPlatform (if needed) (#1176)
* [Xaml] Chain op_implicit for OnPlatform (if needed) For OnPlatform<T>, if a conversion for T to the destination type exists, first convert OnPlatform<T> to T, the T to the dest type Also unify the way we look for op_implicit operators * [Xaml] only apply the double opImplicit if a flag is set * [C] allow conversion on parameter
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/CreateValuesVisitor.cs4
-rw-r--r--Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs28
2 files changed, 28 insertions, 4 deletions
diff --git a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
index b4f9213..99a66fb 100644
--- a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
+++ b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs
@@ -206,7 +206,9 @@ namespace Xamarin.Forms.Xaml
for (var i = 0; i < p.Length; i++) {
if ((p [i].ParameterType.IsAssignableFrom(types [i])))
continue;
- var op_impl = p [i].ParameterType.GetRuntimeMethod("op_Implicit", new [] { types [i]});
+ var op_impl = p[i].ParameterType.GetImplicitConversionOperator(fromType: types[i], toType: p[i].ParameterType)
+ ?? types[i].GetImplicitConversionOperator(fromType: types[i], toType: p[i].ParameterType);
+
if (op_impl == null)
return false;
arguments [i] = op_impl.Invoke(null, new [] { arguments [i]});
diff --git a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
index 14e0b8b..c2137ec 100644
--- a/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/Xamarin.Forms.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Xml;
+using System.Linq;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Xaml
@@ -43,16 +44,37 @@ namespace Xamarin.Forms.Xaml
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 });
+ resource = method.Invoke(null, new[] { resource });
}
return resource;
}
if (propertyType.IsAssignableFrom(resource.GetType()))
return resource;
- var implicit_op = resource.GetType().GetRuntimeMethod("op_Implicit", new [] { resource.GetType() });
- if (implicit_op != null && propertyType.IsAssignableFrom(implicit_op.ReturnType))
+ var implicit_op = resource.GetType().GetImplicitConversionOperator(fromType: resource.GetType(), toType: propertyType)
+ ?? propertyType.GetImplicitConversionOperator(fromType: resource.GetType(), toType: propertyType);
+ if (implicit_op != null)
return implicit_op.Invoke(resource, new [] { resource });
+ //Special case for https://bugzilla.xamarin.com/show_bug.cgi?id=59818
+ //On OnPlatform, check for an opImplicit from the targetType
+ if (Xamarin.Forms.Device.Flags.Contains("xamlDoubleImplicitOpHack")
+ && resource.GetType().GetTypeInfo().IsGenericType
+ && (resource.GetType().GetGenericTypeDefinition() == typeof(OnPlatform<>))) {
+ var tType = resource.GetType().GenericTypeArguments[0];
+ var opImplicit = tType.GetImplicitConversionOperator(fromType: tType, toType: propertyType)
+ ?? propertyType.GetImplicitConversionOperator(fromType: tType, toType: propertyType);
+
+ if (opImplicit != null) {
+ //convert the OnPlatform<T> to T
+ var opPlatformImplicitConversionOperator = resource.GetType().GetImplicitConversionOperator(fromType: resource.GetType(), toType: tType);
+ resource = opPlatformImplicitConversionOperator.Invoke(null, new[] { resource });
+
+ //and convert to toType
+ resource = opImplicit.Invoke(null, new[] { resource });
+ return resource;
+ }
+ }
+
return resource;
}