public static ValueSpecification FromAttribute(ValueAttribute attribute, System.Type conversionType)
 {
     return new ValueSpecification(
         attribute.Index,
         attribute.Required,
         attribute.Min,
         attribute.Max,
         attribute.DefaultValue.ToMaybe(),
         conversionType);
 }
 public static ValueSpecification FromAttribute(ValueAttribute attribute, Type conversionType)
 {
     return new ValueSpecification(
         attribute.Index,
         attribute.Required,
         attribute.Min == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Min),
         attribute.Max == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Max),
         attribute.DefaultValue.ToMaybe(),
         conversionType,
         conversionType.ToTargetType());
 }
 public static ValueSpecification FromAttribute(ValueAttribute attribute, Type conversionType, IEnumerable<string> enumValues)
 {
     return new ValueSpecification(
         attribute.Index,
         attribute.MetaName,
         attribute.Required,
         attribute.Min == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Min),
         attribute.Max == -1 ? Maybe.Nothing<int>() : Maybe.Just(attribute.Max),
         attribute.Default.ToMaybe(),
         attribute.HelpText,
         attribute.MetaValue,
         enumValues,
         conversionType,
         conversionType.ToTargetType());
 }
예제 #4
0
        public static bool Value(this Enum @enum)
        {
            bool value  = false;
            var  fields = @enum.GetType().GetFields();

            foreach (var field in fields)
            {
                ValueAttribute valueAttribute = Attribute.GetCustomAttribute(field,
                                                                             typeof(ValueAttribute)) as ValueAttribute;
                if (valueAttribute != null && field.Name.Equals(@enum.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    value = valueAttribute.Value;
                    break;
                }
            }

            return(value);
        }
예제 #5
0
        /// <summary>
        /// 枚举Lsit信息获取
        /// </summary>
        /// <param name="enumType"></param>
        /// <param name="flgRemoveAll">如果不想要All,设置为true</param>
        /// <returns></returns>
        public static List <EnumItem> GetList(this Type enumType, bool flgRemoveAll = false, EnumLanguage lan = EnumLanguage.CN)
        {
            // 返回值
            List <EnumItem> result = new List <EnumItem>();

            // 枚举遍历
            foreach (var e in Enum.GetValues(enumType))
            {
                EnumItem item = new EnumItem();

                // 获取Index
                item.Index = (int)e;
                // 是否加入All枚举
                if (flgRemoveAll && item.Index == 0)
                {
                    continue;
                }

                // 获取描述
                object[] objArr;
                switch (lan)
                {
                // 中文
                case EnumLanguage.CN:
                    objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
                    if (objArr != null && objArr.Length > 0)
                    {
                        // 中文获取Description特性
                        DescriptionAttribute da = objArr[0] as DescriptionAttribute;
                        item.Description = da.Description;
                    }
                    break;

                // 英文
                case EnumLanguage.EN:
                    objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(EnglishAttribute), true);
                    if (objArr != null && objArr.Length > 0)
                    {
                        // 英文获取Description特性
                        EnglishAttribute da = objArr[0] as EnglishAttribute;
                        item.Description = da.Value;
                    }
                    break;

                // 日文
                default:
                    objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(JapaneseAttribute), true);
                    if (objArr != null && objArr.Length > 0)
                    {
                        // 日文获取Japanese特性
                        JapaneseAttribute da = objArr[0] as JapaneseAttribute;
                        item.Description = da.Value;
                    }
                    break;
                }

                // 获取Value值
                object[] dbValueArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(ValueAttribute), true);
                if (dbValueArr != null && dbValueArr.Length > 0)
                {
                    ValueAttribute da = dbValueArr[0] as ValueAttribute;
                    item.Value = da.Value;
                }

                result.Add(item);
            }
            return(result);
        }
        public void TestZeroElements()
        {
            SetUpFindElementsReturnsEmpty();

            Actor.Invoking(x => x.AsksFor(ValueAttribute.Of(Locator))).Should().Throw <WaitingException <bool> >();
        }
        public void TestAttribute()
        {
            WebDriver.Setup(x => x.FindElement(It.IsAny <By>()).GetAttribute(It.IsAny <string>())).Returns("a");

            Actor.AsksFor(ValueAttribute.Of(Locator)).Should().Be("a");
        }
예제 #8
0
 /// <summary>
 /// Creates a new instance of <see cref="ParsingValueInfo"/>.
 /// </summary>
 /// <param name="propertyInfo">A property to encapsulate.</param>
 /// <param name="attribute">Attribute containing configuration of the value.</param>
 public ParsingValueInfo(PropertyInfo propertyInfo, ValueAttribute attribute) : this(propertyInfo)
     => this.attribute = attribute ?? throw new ArgumentNullException(nameof(attribute));