/// <summary> /// 取指定的成员包装器 /// </summary> /// <param name="memberName"></param> /// <returns></returns> public MemberAccessWrapper GetWrapper(string memberName) { MemberAccessWrapper wrapper = null; this.Wrappers.TryGetValue(memberName, out wrapper); //if (wrapper == null) throw new XfwException("member [{0}.{1}] doesn't exists", _type.Name, memberName); return(wrapper); }
/// <summary> /// 设置指定成员的值 /// </summary> /// <param name="target">拥有该成员的类实例</param> /// <param name="memberName">成员名称</param> /// <param name="value">成员值</param> /// <returns></returns> public void Set(object target, string memberName, object value) { MemberAccessWrapper wrapper = this.GetWrapper(memberName); wrapper.Set(target, value); }
/// <summary> /// 取指定成员的值 /// </summary> /// <param name="target">拥有该成员的类实例</param> /// <param name="memberName">成员名称</param> /// <returns></returns> public object Get(object target, string memberName) { MemberAccessWrapper wrapper = this.GetWrapper(memberName); return(wrapper.Get(target)); }
/// <summary> /// 取指定的成员包装器自定义特性。 /// </summary> /// <typeparam name="TAttribute">自定义特性</typeparam> /// <returns></returns> public TAttribute GetWrapperAttribute <TAttribute>(string memberName) where TAttribute : Attribute { MemberAccessWrapper wrapper = this.GetWrapper(memberName); return(wrapper != null?wrapper.GetCustomAttribute <TAttribute>() : null); }