summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-14 13:50:15 +0100
committerGitHub <noreply@github.com>2016-12-14 13:50:15 +0100
commit859b05887415ffdb1453065ee37cf225ca869523 (patch)
tree81eedba6697457fe124b72004aaf36ae463b18d0 /Xamarin.Forms.Build.Tasks
parentd4792dc98dfca29849bedc21519d9cf9ae6f2cb6 (diff)
downloadxamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.tar.gz
xamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.tar.bz2
xamarin-forms-859b05887415ffdb1453065ee37cf225ca869523.zip
Xamlc compiled trigger (#629)
* [XamlC] compiled Trigger * remove file header * name bool parameters
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs3
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs40
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj1
3 files changed, 42 insertions, 2 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
index 163bd9e7..482ee7c6 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
@@ -1,5 +1,4 @@
-´╗┐using System;
-using System.Collections.Generic;
+´╗┐using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
new file mode 100644
index 00000000..c2875c7c
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+using Xamarin.Forms.Xaml;
+using Xamarin.Forms.Build.Tasks;
+
+namespace Xamarin.Forms.Core.XamlC
+{
+
+ class TriggerValueProvider : ICompiledValueProvider
+ {
+ public IEnumerable<Instruction> ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context)
+ {
+ var valueNode = ((IElementNode)node).Properties[new XmlName("", "Value")];
+
+ //if it's an elementNode, there's probably no need to convert it
+ if (valueNode is IElementNode)
+ yield break;
+
+ var value = ((string)((ValueNode)valueNode).Value);
+ var bpNode = ((ValueNode)((IElementNode)node).Properties[new XmlName("", "Property")]);
+ var bpRef = (new BindablePropertyConverter()).GetBindablePropertyFieldReference((string)bpNode.Value, module, bpNode);
+
+ TypeReference _;
+ var setValueRef = module.Import(module.Import(typeof(Trigger)).GetProperty(p => p.Name == "Value", out _).SetMethod);
+
+ //push the setter
+ yield return Instruction.Create(OpCodes.Ldloc, vardefref.VariableDefinition);
+
+ //push the value
+ foreach (var instruction in ((ValueNode)valueNode).PushConvertedValue(context, bpRef, valueNode.PushServiceProvider(context, bpRef: bpRef), boxValueTypes: true, unboxValueTypes: false))
+ yield return instruction;
+
+ //set the value
+ yield return Instruction.Create(OpCodes.Callvirt, setValueRef);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index 51dd60be..ac7d6f13 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -107,6 +107,7 @@
<Compile Include="CompiledConverters\TypeTypeConverter.cs" />
<Compile Include="CompiledValueProviders\SetterValueProvider.cs" />
<Compile Include="CompiledValueProviders\ICompiledValueProvider.cs" />
+ <Compile Include="CompiledValueProviders\TriggerValueProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">