summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs')
-rw-r--r--Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs18
1 files changed, 15 insertions, 3 deletions
diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
index 397ea526..44678d26 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));