var value = ((ValueNode)valueNode).Value;
yield return Create(Ldloc, parent);
- if (context.Root is VariableDefinition)
- foreach (var instruction in (context.Root as VariableDefinition).LoadAs(adder.Parameters[0].ParameterType.ResolveGenericParameters(adder), module))
- yield return instruction;
- else if (context.Root is FieldDefinition) {
- yield return Create(Ldarg_0);
- yield return Create(Ldfld, context.Root as FieldDefinition);
- } else
- throw new InvalidProgramException();
var declaringType = context.Body.Method.DeclaringType;
while (declaringType.IsNested)
declaringType = declaringType.DeclaringType;
throw new XamlParseException($"Signature (parameter {i}) of EventHandler \"{context.Body.Method.DeclaringType.FullName}.{value}\" doesn't match the event type", iXmlLineInfo);
//TODO check generic parameters if any
+ //FIXME: eventually get the right ctor instead fo the First() one, just in case another one could exists (not even sure it's possible).
+ var ctor = module.ImportReference(eventinfo.EventType.ResolveCached().GetConstructors().First());
+ ctor = ctor.ResolveGenericParameters(eventinfo.EventType, module);
+
+ if (handler.IsStatic) {
+ yield return Create(Ldnull);
+ } else {
+ if (context.Root is VariableDefinition)
+ foreach (var instruction in (context.Root as VariableDefinition).LoadAs(ctor.Parameters[0].ParameterType.ResolveGenericParameters(ctor), module))
+ yield return instruction;
+ else if (context.Root is FieldDefinition) {
+ yield return Create(Ldarg_0);
+ yield return Create(Ldfld, context.Root as FieldDefinition);
+ } else
+ throw new InvalidProgramException();
+ }
+
if (handler.IsVirtual) {
yield return Create(Ldarg_0);
yield return Create(Ldvirtftn, handler);
} else
yield return Create(Ldftn, handler);
- //FIXME: eventually get the right ctor instead fo the First() one, just in case another one could exists (not even sure it's possible).
- var ctor = module.ImportReference(eventinfo.EventType.ResolveCached().GetConstructors().First());
- ctor = ctor.ResolveGenericParameters(eventinfo.EventType, module);
yield return Create(Newobj, module.ImportReference(ctor));
//Check if the handler has the same signature as the ctor (it should)
yield return Create(Callvirt, module.ImportReference(adder));
baseForVirtualClicked++;
}
+ protected static int staticClicked;
+
+ // This is necessary because the interpreter searches the class
+ // specified by x:Class for a static method.
+ // See: https://github.com/xamarin/Xamarin.Forms/issues/5100
+ static void HandleStaticClicked(object sender, EventArgs e)
+ {
+ staticClicked++;
+ }
+
[TestFixture]
public class Tests
{
Assert.AreEqual(0, layout.baseForVirtualClicked);
Assert.AreEqual(1, layout.overrideClicked);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void TestStaticHandler(bool useCompiledXaml)
+ {
+ try
+ {
+ var layout = new SubForEvents(useCompiledXaml);
+ Assert.AreEqual(0, staticClicked);
+ layout.elementWithStaticHandler.SendClicked();
+ Assert.AreEqual(1, staticClicked);
+ }
+ finally
+ {
+ staticClicked = 0;
+ }
+ }
}
}
#pragma warning restore 1998
{
}
+
+ // This is necessary because the interpreter searches the subclass
+ // for a static method.
+ // See: https://github.com/xamarin/Xamarin.Forms/issues/5100
+ static void HandleStaticClicked(object sender, EventArgs e)
+ {
+ staticClicked++;
+ }
}
}
\ No newline at end of file