summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs')
-rw-r--r--Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs b/Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs
new file mode 100644
index 00000000..41d7cb20
--- /dev/null
+++ b/Xamarin.Forms.Build.Tasks/MethodDefinitionExtensions.cs
@@ -0,0 +1,38 @@
+´╗┐using System.Collections.Generic;
+using Mono.Cecil;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Build.Tasks
+{
+ static class MethodDefinitionExtensions
+ {
+ public static bool MatchXArguments(this MethodDefinition methodDefinition, ElementNode enode, ModuleDefinition module)
+ {
+ if (!enode.Properties.ContainsKey(XmlName.xArguments))
+ return !methodDefinition.HasParameters;
+
+ var arguments = new List<INode>();
+ var node = enode.Properties[XmlName.xArguments] as ElementNode;
+ if (node != null)
+ arguments.Add(node);
+ var list = enode.Properties[XmlName.xArguments] as ListNode;
+ if (list != null)
+ {
+ foreach (var n in list.CollectionItems)
+ arguments.Add(n);
+ }
+
+ if (methodDefinition.Parameters.Count != arguments.Count)
+ return false;
+
+ for (var i = 0; i < methodDefinition.Parameters.Count; i++)
+ {
+ var paramType = methodDefinition.Parameters[i].ParameterType;
+ var argType = ((IElementNode)arguments[i]).XmlType.GetTypeReference(module, null);
+ if (!argType.InheritsFromOrImplements(paramType))
+ return false;
+ }
+ return true;
+ }
+ }
+} \ No newline at end of file