-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathElementExtensions.cs
41 lines (34 loc) · 1.46 KB
/
ElementExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
{
using System;
using System.Reflection;
using NativeCode.Mobile.AppCompat.Helpers;
using Xamarin.Forms;
/// <summary>
/// Provides extensions for <see cref="Element" /> instances.
/// </summary>
public static class ElementExtensions
{
private const string ButtonControllerType = "Xamarin.Forms.IButtonController, Xamarin.Forms.Core";
private const string ButtonControllerSendClicked = "SendClicked";
private static readonly MethodInfo MethodSendClicked;
/// <summary>
/// Initializes static members of the <see cref="ElementExtensions"/> class.
/// </summary>
static ElementExtensions()
{
var type = Type.GetType(ButtonControllerType, true);
MethodSendClicked = type.GetMethod(ButtonControllerSendClicked);
}
/// <summary>
/// Tries to cast the element to a button controller and invoke the SendClicked method.
/// </summary>
/// <param name="element">The element.</param>
/// <exception cref="System.MissingMethodException">Could not find SendClicked method.</exception>
/// <remarks>The IButtonController is an internal interface, so we have to use reflection.</remarks>
public static void InvokeSendClicked(this Element element)
{
MethodSendClicked.Invoke(element, ReflectionHelper.EmptyParameters);
}
}
}