summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-04 21:08:11 (GMT)
committerGitHub <noreply@github.com>2016-12-04 21:08:11 (GMT)
commit39f2deb5e04886374e720013782c751a4bb7675d (patch)
tree64f2df7230760c26533730e73821a6dc5c7607da /Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions
parentfb76107f4f3294a9d32c6983bc742ce8dff60cd8 (diff)
downloadxamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.zip
xamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.tar.gz
xamarin-forms-39f2deb5e04886374e720013782c751a4bb7675d.tar.bz2
[Xaml] support arrays as x:Arguments (#545)
* [Xaml] port some FactoryMethod tests to XamlC * [Xaml] support array parameters in factory ctors * [XamlC] support arrays as x:Arguments * fix build
Diffstat (limited to 'Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions')
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ArrayExtension.cs31
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ICompiledMarkupExtension.cs2
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs7
3 files changed, 35 insertions, 5 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ArrayExtension.cs b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ArrayExtension.cs
new file mode 100644
index 0000000..0626114
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ArrayExtension.cs
@@ -0,0 +1,31 @@
+using System.Collections.Generic;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+using Mono.Cecil.Rocks;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Build.Tasks
+{
+ class ArrayExtension : ICompiledMarkupExtension
+ {
+ public IEnumerable<Instruction> ProvideValue(IElementNode node, ModuleDefinition module, ILContext context, out TypeReference memberRef)
+ {
+ var typeNode = node.Properties[new XmlName("", "Type")] as IElementNode;
+ var typeTypeRef = context.TypeExtensions[typeNode];
+ var n = node.CollectionItems.Count;
+
+ var instructions = new List<Instruction>();
+ instructions.Add(Instruction.Create(OpCodes.Ldc_I4, n));
+ instructions.Add(Instruction.Create(OpCodes.Newarr, typeTypeRef));
+
+ memberRef = typeTypeRef.MakeArrayType();
+ for (var i = 0; i < n; i++) {
+ instructions.Add(Instruction.Create(OpCodes.Dup));
+ instructions.Add(Instruction.Create(OpCodes.Ldc_I4, i));
+ instructions.Add(Instruction.Create(OpCodes.Ldloc, context.Variables[node.CollectionItems[i] as IElementNode]));
+ instructions.Add(Instruction.Create(OpCodes.Stelem_Ref));
+ }
+ return instructions;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ICompiledMarkupExtension.cs b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ICompiledMarkupExtension.cs
index b18d956..285a536 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ICompiledMarkupExtension.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/ICompiledMarkupExtension.cs
@@ -7,6 +7,6 @@ namespace Xamarin.Forms.Build.Tasks
{
interface ICompiledMarkupExtension
{
- IEnumerable<Instruction> ProvideValue(IElementNode node, ModuleDefinition module, out TypeReference typeRef);
+ IEnumerable<Instruction> ProvideValue(IElementNode node, ModuleDefinition module, ILContext context, out TypeReference typeRef);
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
index 14797c5..014fb82 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
@@ -1,5 +1,4 @@
-´╗┐using System;
-using System.Collections.Generic;
+´╗┐using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Xamarin.Forms.Xaml;
@@ -11,11 +10,11 @@ namespace Xamarin.Forms.Build.Tasks
{
class StaticExtension : ICompiledMarkupExtension
{
- public IEnumerable<Instruction> ProvideValue(IElementNode node, ModuleDefinition module, out TypeReference memberRef)
+ public IEnumerable<Instruction> ProvideValue(IElementNode node, ModuleDefinition module, ILContext context, out TypeReference memberRef)
{
INode ntype;
if (!node.Properties.TryGetValue(new XmlName("", "Member"), out ntype))
- ntype = node.CollectionItems [0];
+ ntype = node.CollectionItems[0];
var member = ((ValueNode)ntype).Value as string;
if (IsNullOrEmpty(member) || !member.Contains(".")) {