summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-01 21:34:39 (GMT)
committerGitHub <noreply@github.com>2016-12-01 21:34:39 (GMT)
commite413e0cf331ae1512e2d8a6fcc89446c1cf2225c (patch)
tree5aad168ffd3e0679bb36b4a54f5465e501629411 /Xamarin.Forms.Build.Tasks
parent00b652cd43902b4499706d1f9172041c20083ae8 (diff)
downloadxamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.zip
xamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.tar.gz
xamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.tar.bz2
[XamlC] use op_implicit where we should (#580)
* [XamlC] (passing) test for 48242 * [XamlC] (failing) test for 48242 * [XamlC] more op_implicit conversions * additional test * fix rebase
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs18
-rw-r--r--Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs7
2 files changed, 19 insertions, 6 deletions
diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
index 397ea52..44678d2 100644
--- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
@@ -857,6 +857,10 @@ namespace Xamarin.Forms.Build.Tasks
// Worst case scenario ? InvalidCastException at runtime
if (attached && varValue.VariableType.FullName == "System.Object")
return true;
+ var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(bpTypeRef, module);
+ if (implicitOperator != null)
+ return true;
+
return varValue.VariableType.InheritsFromOrImplements(bpTypeRef);
}
@@ -879,9 +883,17 @@ namespace Xamarin.Forms.Build.Tasks
foreach (var instruction in valueNode.PushConvertedValue(context, bpRef, valueNode.PushServiceProvider(context, bpRef:bpRef), true, false))
yield return instruction;
} else if (elementNode != null) {
- yield return Instruction.Create(OpCodes.Ldloc, context.Variables [elementNode]);
- if (context.Variables [elementNode].VariableType.IsValueType)
- yield return Instruction.Create(OpCodes.Box, context.Variables [elementNode].VariableType);
+ var bpTypeRef = bpRef.GetBindablePropertyType(iXmlLineInfo, module);
+ var varDef = context.Variables[elementNode];
+ var varType = varDef.VariableType;
+ var implicitOperator = varDef.VariableType.GetImplicitOperatorTo(bpTypeRef, module);
+ yield return Instruction.Create(OpCodes.Ldloc, varDef);
+ if (implicitOperator != null) {
+ yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
+ varType = module.Import(bpTypeRef);
+ }
+ if (varType.IsValueType)
+ yield return Instruction.Create(OpCodes.Box, varType);
}
yield return Instruction.Create(OpCodes.Callvirt, module.Import(setValue));
diff --git a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
index f0a6cef..d0ccbc5 100644
--- a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
@@ -204,9 +204,10 @@ namespace Xamarin.Forms.Build.Tasks
}
public static MethodReference GetImplicitOperatorTo(this TypeReference fromType, TypeReference toType, ModuleDefinition module)
- {
- var implicitOperators = fromType.GetMethods(md => md.IsPublic && md.IsStatic && md.IsSpecialName && md.Name == "op_Implicit",
- module).ToList();
+ {
+ var implicitOperatorsOnFromType = fromType.GetMethods(md => md.IsPublic && md.IsStatic && md.IsSpecialName && md.Name == "op_Implicit", module);
+ var implicitOperatorsOnToType = toType.GetMethods(md => md.IsPublic && md.IsStatic && md.IsSpecialName && md.Name == "op_Implicit", module);
+ var implicitOperators = implicitOperatorsOnFromType.Concat(implicitOperatorsOnToType).ToList();
if (implicitOperators.Any()) {
foreach (var op in implicitOperators) {
var cast = op.Item1;