Beispiel #1
0
        private static Expression Call(Expression param, MemberParseInfo info, int i)
        {
            var call = (Expression)null;

            if (info.Info is PropertyInfo propertyInfo)
            {
                if (info.Index != null)
                {
                    var index = Expression.Constant(info.Index, info.Index.GetType());
                    call = Expression.Property(param, propertyInfo, index);
                }
                else
                {
                    call = Expression.Property(param, propertyInfo);
                }
            }
            else if (info.Info is FieldInfo fieldInfo)
            {
                call = Expression.Field(param, fieldInfo);
            }
            else if (info.Info is MethodInfo methodInfo)
            {
                call = Expression.Call(param, methodInfo);
            }

            return(call);
        }
Beispiel #2
0
        public object GetValue(MemberParseInfo info, object target)
        {
            switch (info.Info)
            {
            case PropertyInfo pInfo:
                return(info.Index != null?pInfo.GetValue(target, new object[] { info.Index }) : pInfo.GetValue(target));

            case FieldInfo fInfo:
                return(fInfo.GetValue(target));

            case MethodInfo mInfo:
                return(mInfo.Invoke(target, null));
            }
            return(null);
        }
Beispiel #3
0
        public void SetValue(MemberParseInfo info, object target, object value)
        {
            switch (info.Info)
            {
            case PropertyInfo pInfo:
                if (info.Index != null)
                {
                    pInfo.SetValue(target, value, new object[] { info.Index });
                }
                else
                {
                    pInfo.SetValue(target, value);
                }
                break;

            case FieldInfo fInfo:
                fInfo.SetValue(target, value);
                break;
            }
        }