示例#1
0
 public static ImeAction GetValueFromDescription(this KeyboardReturnType value)
 {
     try
     {
         var type = typeof(ImeAction);
         if (!type.IsEnum)
         {
             throw new InvalidOperationException();
         }
         foreach (var field in type.GetFields())
         {
             var attribute = Attribute.GetCustomAttribute(field,
                                                          typeof(DescriptionAttribute)) as DescriptionAttribute;
             if (attribute != null)
             {
                 if (attribute.Description == value.ToString())
                 {
                     return((ImeAction)field.GetValue(null));
                 }
             }
             else
             {
                 if (field.Name == value.ToString())
                 {
                     return((ImeAction)field.GetValue(null));
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     throw new NotSupportedException($"Not supported on Android: {value}");
 }
        public static UIReturnKeyType GetValueFromDescription(this KeyboardReturnType value)
        {
            var type = typeof(UIReturnKeyType);

            if (!type.IsEnum)
            {
                throw new InvalidOperationException();
            }
            foreach (var field in type.GetFields())
            {
                var attribute = Attribute.GetCustomAttribute(field,
                                                             typeof(DescriptionAttribute)) as DescriptionAttribute;
                if (attribute != null)
                {
                    if (attribute.Description == value.ToString())
                    {
                        return((UIReturnKeyType)field.GetValue(null));
                    }
                }
                else
                {
                    if (field.Name == value.ToString())
                    {
                        return((UIReturnKeyType)field.GetValue(null));
                    }
                }
            }
            throw new NotSupportedException($"Not supported on iOS: {value}");
        }