예제 #1
0
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="target">拥有该成员的类实例</param>
        /// <returns></returns>
        private object Get(object target)
        {
            if (!this.Member.CanRead)
            {
                throw new XFrameworkException("{0} is unreadable", base.FullName);
            }

            if (_getter == null)
            {
                _getter = PropertyAccessor.InitializeGetter(this.Member);
            }
            return(_getter(target));
        }
예제 #2
0
        /// <summary>
        /// 创建成员反射器
        /// </summary>
        /// <param name="member">元数据</param>
        /// <returns></returns>
        public static MemberAccessorBase Create(MemberInfo member)
        {
            MemberAccessorBase m = null;

            if (member.MemberType == MemberTypes.Property)
            {
                m = new PropertyAccessor((PropertyInfo)member);
            }
            else if (member.MemberType == MemberTypes.Field)
            {
                m = new FieldAccessor((FieldInfo)member);
            }
            else if (member.MemberType == MemberTypes.Method)
            {
                m = new MethodAccessor((MethodInfo)member);
            }

            if (m == null)
            {
                throw new XFrameworkException("{0}.{1} not supported", member.ReflectedType, member.Name);
            }
            return(m);
        }