Beispiel #1
0
        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="expression">表达式</param>
        public object GetValue(Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }
            var result = Lambdas.GetValue(expression);

            if (result == null)
            {
                return(null);
            }
            var type = result.GetType();

            if (type.IsEnum)
            {
                return(Enum.GetValue(type, result));
            }
            return(result);
        }
Beispiel #2
0
 public void Test_GetValue_Nullable(object member, int value)
 {
     Assert.Equal(value, Enum.GetValue <EnumSample?>(member));
 }
Beispiel #3
0
 public void Test_GetValue_Validate()
 {
     AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <EnumSample>(null), "member");
     AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <EnumSample>(string.Empty), "member");
     AssertHelper.Throws <ArgumentNullException>(() => Enum.GetValue <Sample>(string.Empty), "member");
 }