diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-12-12 10:14:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 10:14:37 +0100 |
commit | 1c796c3a9edfa6a5f16689e5e7ea775c8ef21339 (patch) | |
tree | 9ad7e425766ea73b18756553cfca4548aee36fef /Xamarin.Forms.Build.Tasks | |
parent | 899e2bd591bf33cf99c1db95666f1313ff80565b (diff) | |
download | xamarin-forms-1c796c3a9edfa6a5f16689e5e7ea775c8ef21339.tar.gz xamarin-forms-1c796c3a9edfa6a5f16689e5e7ea775c8ef21339.tar.bz2 xamarin-forms-1c796c3a9edfa6a5f16689e5e7ea775c8ef21339.zip |
[XamlC] support setting values on ValueTypes (#596)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r-- | Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 44678d26..35316f26 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -953,12 +953,19 @@ namespace Xamarin.Forms.Build.Tasks var valueNode = node as ValueNode; var elementNode = node as IElementNode; - yield return Instruction.Create(OpCodes.Ldloc, parent); + //if it's a value type, load the address so we can invoke methods on it + if (parent.VariableType.IsValueType) + yield return Instruction.Create(OpCodes.Ldloca, parent); + else + yield return Instruction.Create(OpCodes.Ldloc, parent); if (valueNode != null) { foreach (var instruction in valueNode.PushConvertedValue(context, propertyType, new ICustomAttributeProvider [] { property, propertyType.Resolve() }, valueNode.PushServiceProvider(context, propertyRef:property), false, true)) yield return instruction; - yield return Instruction.Create(OpCodes.Callvirt, propertySetterRef); + if (parent.VariableType.IsValueType) + yield return Instruction.Create(OpCodes.Call, propertySetterRef); + else + yield return Instruction.Create(OpCodes.Callvirt, propertySetterRef); } else if (elementNode != null) { var vardef = context.Variables [elementNode]; var implicitOperator = vardef.VariableType.GetImplicitOperatorTo(propertyType, module); @@ -970,7 +977,10 @@ namespace Xamarin.Forms.Build.Tasks yield return Instruction.Create(OpCodes.Unbox_Any, module.Import(propertyType)); else if (vardef.VariableType.IsValueType && propertyType.FullName == "System.Object") yield return Instruction.Create(OpCodes.Box, vardef.VariableType); - yield return Instruction.Create(OpCodes.Callvirt, propertySetterRef); + if (parent.VariableType.IsValueType) + yield return Instruction.Create(OpCodes.Call, propertySetterRef); + else + yield return Instruction.Create(OpCodes.Callvirt, propertySetterRef); } } |