diff options
Diffstat (limited to 'Xamarin.Forms.Core/KeyboardTypeConverter.cs')
-rw-r--r-- | Xamarin.Forms.Core/KeyboardTypeConverter.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/KeyboardTypeConverter.cs b/Xamarin.Forms.Core/KeyboardTypeConverter.cs new file mode 100644 index 00000000..4a93010b --- /dev/null +++ b/Xamarin.Forms.Core/KeyboardTypeConverter.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace Xamarin.Forms +{ + public class KeyboardTypeConverter : TypeConverter + { + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + string[] parts = value.Split('.'); + if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Keyboard")) + { + string keyboard = parts[parts.Length - 1]; + FieldInfo field = typeof(Keyboard).GetFields().FirstOrDefault(fi => fi.IsStatic && fi.Name == keyboard); + if (field != null) + return (Keyboard)field.GetValue(null); + PropertyInfo property = typeof(Keyboard).GetProperties().FirstOrDefault(pi => pi.Name == keyboard && pi.CanRead && pi.GetMethod.IsStatic); + if (property != null) + return (Keyboard)property.GetValue(null, null); + } + } + + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Keyboard))); + } + } +}
\ No newline at end of file |