summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-07 10:35:32 (GMT)
committerGitHub <noreply@github.com>2016-12-07 10:35:32 (GMT)
commit7851541ab67c1e3c1d38b3210a1153d08ce78ab2 (patch)
tree55efc79b32a427f5a4cc1674a3566ef2e2a507c3 /Xamarin.Forms.Xaml
parent8181e6d4cbe8aac6eb29c5140262d8bc51dba7b7 (diff)
downloadxamarin-forms-7851541ab67c1e3c1d38b3210a1153d08ce78ab2.zip
xamarin-forms-7851541ab67c1e3c1d38b3210a1153d08ce78ab2.tar.gz
xamarin-forms-7851541ab67c1e3c1d38b3210a1153d08ce78ab2.tar.bz2
[Xaml[C]] support op_implicit declared on Target (#585)
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r--Xamarin.Forms.Xaml/TypeConversionExtensions.cs33
1 files changed, 28 insertions, 5 deletions
diff --git a/Xamarin.Forms.Xaml/TypeConversionExtensions.cs b/Xamarin.Forms.Xaml/TypeConversionExtensions.cs
index a29b3af..15a66f5 100644
--- a/Xamarin.Forms.Xaml/TypeConversionExtensions.cs
+++ b/Xamarin.Forms.Xaml/TypeConversionExtensions.cs
@@ -170,11 +170,34 @@ namespace Xamarin.Forms.Xaml
}
//if there's an implicit conversion, convert
- if (value != null)
- {
- var cast = value.GetType().GetRuntimeMethod("op_Implicit", new[] { value.GetType() });
- if (cast != null && cast.ReturnType == toType) {
- value = cast.Invoke(null, new [] { value });
+ if (value != null) {
+ MethodInfo opImplicit = null;
+ foreach (var mi in value.GetType().GetRuntimeMethods()) {
+ if (!mi.IsSpecialName) continue;
+ if (mi.Name != "op_Implicit") continue;
+ if (!mi.IsPublic) continue;
+ if (mi.ReturnType != toType) continue;
+ var parameters = mi.GetParameters();
+ if (parameters.Length != 1) continue;
+ if (parameters[0].ParameterType != value.GetType()) continue;
+ opImplicit = mi;
+ break;
+ }
+ if (opImplicit == null) {
+ foreach (var mi in toType.GetRuntimeMethods()) {
+ if (!mi.IsSpecialName) continue;
+ if (mi.Name != "op_Implicit") continue;
+ if (!mi.IsPublic) continue;
+ if (mi.ReturnType != toType) continue;
+ var parameters = mi.GetParameters();
+ if (parameters.Length != 1) continue;
+ if (parameters[0].ParameterType != value.GetType()) continue;
+ opImplicit = mi;
+ break;
+ }
+ }
+ if (opImplicit != null) {
+ value = opImplicit.Invoke(null, new[] { value });
return value;
}
}