Exemplo n.º 1
0
 /// <summary>
 /// 获取字段值
 /// </summary>
 /// <param name="target">拥有该成员的类实例</param>
 /// <returns></returns>
 private object Get(object target)
 {
     if (_get == null)
     {
         _get = FieldInvoker.InitializeGetter(_member);
     }
     return(_get(target));
 }
Exemplo n.º 2
0
 /// <summary>
 /// 设置字段值
 /// </summary>
 /// <param name="target">拥有该成员的类实例</param>
 /// <param name="value">字段/属性值</param>
 private void Set(object target, object value)
 {
     if (_set == null)
     {
         _set = FieldInvoker.InitializeSetter(_member);
     }
     value = value ?? TypeUtils.GetNullValue(_member.FieldType);
     _set(target, value);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 创建成员反射器
        /// </summary>
        /// <param name="member">元数据</param>
        /// <returns></returns>
        public static MemberInvokerBase Create(MemberInfo member)
        {
            MemberInvokerBase invoker = null;

            if (member.MemberType == MemberTypes.Property)
            {
                invoker = new PropertyInvoker((PropertyInfo)member);
            }
            if (member.MemberType == MemberTypes.Field)
            {
                invoker = new FieldInvoker((FieldInfo)member);
            }
            if (member.MemberType == MemberTypes.Method)
            {
                invoker = new MethodInvoker((MethodInfo)member);
            }
            if (invoker == null)
            {
                throw new XFrameworkException("{0}.{1} not supported", member.ReflectedType, member.Name);
            }
            return(invoker);
        }