/// <summary> /// 使用指定的名字和访问委托,初始化 <see cref="MemberAccessor{T}"/> 类的新实例。 /// </summary> /// <param name="name">属性或字段的名字。</param> /// <param name="getDelegate">用于获取属性或字段的委托。</param> /// <param name="setDelegate">用于设置属性或字段的委托。</param> /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception> /// <exception cref="ArgumentException"><paramref name="getDelegate"/> 和 <paramref name="setDelegate"/> /// 全部为 <c>null</c>。</exception> /// <overloads> /// <summary> /// 初始化 <see cref="MemberAccessor{T}"/> 类的新实例。 /// </summary> /// </overloads> public MemberAccessor(string name, Func <T> getDelegate, Action <T> setDelegate) { CommonExceptions.CheckStringEmpty(name, nameof(name)); if (getDelegate == null && setDelegate == null) { throw CommonExceptions.ArgumentBothNull(nameof(getDelegate), nameof(setDelegate)); } Contract.EndContractBlock(); this.name = name; this.getDelegate = getDelegate; this.setDelegate = setDelegate; }
/// <summary> /// 使用指定的名字和访问委托,初始化 <see cref="MemberAccessor{TTarget, TValue}"/> 类的新实例。 /// </summary> /// <param name="name">实例属性或字段的名字。</param> /// <param name="getDelegate">用于获取实例属性或字段的委托。</param> /// <param name="setDelegate">用于设置实例属性或字段的委托。</param> /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception> /// <exception cref="ArgumentException"><paramref name="getDelegate"/> 和 <paramref name="setDelegate"/> /// 全部为 <c>null</c>。</exception> /// <overloads> /// <summary> /// 初始化 <see cref="MemberAccessor{TTarget, TValue}"/> 类的新实例。 /// </summary> /// </overloads> public MemberAccessor(string name, Func <TTarget, TValue> getDelegate, Action <TTarget, TValue> setDelegate) { CommonExceptions.CheckStringEmpty(name, "name"); if (getDelegate == null && setDelegate == null) { throw CommonExceptions.ArgumentBothNull("getDelegate", "setDelegate"); } Contract.EndContractBlock(); this.name = name; this.getDelegate = getDelegate; this.setDelegate = setDelegate; }