Skip to content

Commit c32247b

Browse files
author
Michael Pham
committed
More refactoring of reflection helpers.
1 parent 4f9e2b8 commit c32247b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/NativeCode.Mobile.AppCompat.Renderers/Extensions/EntryExtensions.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ public static class EntryExtensions
1313
{
1414
private const string EntrySendCompleted = "SendCompleted";
1515

16-
private const BindingFlags InstanceNonPublic = BindingFlags.Instance | BindingFlags.NonPublic;
17-
1816
private static readonly MethodInfo MethodSendCompleted;
1917

2018
/// <summary>
@@ -23,7 +21,7 @@ public static class EntryExtensions
2321
static EntryExtensions()
2422
{
2523
var type = typeof(Entry);
26-
MethodSendCompleted = type.GetMethod(EntrySendCompleted, InstanceNonPublic);
24+
MethodSendCompleted = type.GetMethod(EntrySendCompleted, ReflectionHelper.InstanceNonPublic);
2725
}
2826

2927
/// <summary>

src/NativeCode.Mobile.AppCompat.Renderers/Helpers/KeyboardHelper.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Helpers
99

1010
using View = Android.Views.View;
1111

12-
internal static class KeyboardHelper
12+
public static class KeyboardHelper
1313
{
1414
private const string KeyboardExtensionsType = "Xamarin.Forms.Platform.Android.KeyboardExtensions, Xamarin.Forms.Platform.Android";
1515

@@ -21,8 +21,6 @@ internal static class KeyboardHelper
2121

2222
private const string KeyboardManagerShowKeyboard = "ShowKeyboard";
2323

24-
private const BindingFlags StaticInternalMethods = BindingFlags.NonPublic | BindingFlags.Static;
25-
2624
private static readonly MethodInfo MethodToInputType;
2725

2826
private static readonly MethodInfo MethodHideKeyboard;
@@ -38,8 +36,8 @@ static KeyboardHelper()
3836
MethodToInputType = keyboardExtensionsType.GetMethod(KeyboardExtensionsToInputType);
3937

4038
var keyboardManagerType = Type.GetType(KeyboardManagerType, true);
41-
MethodHideKeyboard = keyboardManagerType.GetMethod(KeyboardManagerHideKeyboard, StaticInternalMethods);
42-
MethodShowKeyboard = keyboardManagerType.GetMethod(KeyboardManagerShowKeyboard, StaticInternalMethods);
39+
MethodHideKeyboard = keyboardManagerType.GetMethod(KeyboardManagerHideKeyboard, ReflectionHelper.InternalStatic);
40+
MethodShowKeyboard = keyboardManagerType.GetMethod(KeyboardManagerShowKeyboard, ReflectionHelper.InternalStatic);
4341
}
4442

4543
public static InputTypes GetInputType(Keyboard keyboard)

src/NativeCode.Mobile.AppCompat.Renderers/Helpers/ReflectionHelper.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Helpers
33
using System;
44
using System.Reflection;
55

6-
internal static class ReflectionHelper
6+
public static class ReflectionHelper
77
{
8+
public const BindingFlags InstanceNonPublic = BindingFlags.Instance | BindingFlags.NonPublic;
9+
10+
public const BindingFlags InternalStatic = BindingFlags.NonPublic | BindingFlags.Static;
11+
812
public static readonly object[] EmptyParameters = new object[0];
913

1014
public static void SetFieldValue(object instance, string name, object value)
1115
{
12-
var field = instance.GetType().GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
16+
var field = instance.GetType().GetField(name, InstanceNonPublic);
1317

1418
if (field == null)
1519
{

0 commit comments

Comments
 (0)