Esempio n. 1
0
        /// <summary>
        /// 使用指定的标识符初始化 <see cref="ProcessorAttribute"/> 类的新实例。
        /// </summary>
        /// <param name="id">处理器的标识符。</param>
        /// <exception cref="ArgumentException"><paramref name="id"/> 为 <c>null</c> 或空字符串。</exception>
        public ProcessorAttribute(string id)
        {
            CommonExceptions.CheckStringEmpty(id, nameof(id));

            Contract.EndContractBlock();
            _id = id;
        }
Esempio n. 2
0
 /// <summary>
 /// 使用实例属性或字段的名称,初始化 <see cref="MemberAccessor{TTarget, TValue}"/> 类的新实例,
 /// 表示 <typeparamref name="TTarget"/> 中的的实例属性或字段。
 /// </summary>
 /// <param name="name">实例属性或字段的名称。</param>
 /// <param name="nonPublic">指示是否应访问非公共实例属性或字段。
 /// 如果要访问非公共实例属性或字段,则为 <c>true</c>;否则为 <c>false</c>。</param>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(string name, bool nonPublic)
 {
     CommonExceptions.CheckStringEmpty(name, nameof(name));
     Contract.EndContractBlock();
     this.name = name;
     Init(typeof(TTarget), nonPublic);
 }
Esempio n. 3
0
 /// <summary>
 /// 使用实例属性或字段的名称,初始化 <see cref="MemberAccessor{TTarget, TValue}"/> 类的新实例,
 /// 表示 <typeparamref name="TTarget"/> 中的的实例属性或字段。
 /// </summary>
 /// <param name="name">实例属性或字段的名称。</param>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(string name)
 {
     CommonExceptions.CheckStringEmpty(name, "name");
     Contract.EndContractBlock();
     this.name = name;
     this.Init(typeof(TTarget), false);
 }
Esempio n. 4
0
 /// <summary>
 /// 使用包含静态属性或字段的类型和名称,初始化 <see cref="MemberAccessor{T}"/> 类的新实例,
 /// 表示指定的静态属性或字段。
 /// </summary>
 /// <param name="targetType">包含静态属性或字段的类型。</param>
 /// <param name="name">属性或字段的名称。</param>
 /// <param name="nonPublic">指示是否应访问非公共属性或字段。
 /// 如果要访问非公共属性或字段,则为 <c>true</c>;否则为 <c>false</c>。</param>
 /// <exception cref="ArgumentNullException"><paramref name="targetType"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(Type targetType, string name, bool nonPublic)
 {
     CommonExceptions.CheckArgumentNull(targetType, nameof(targetType));
     CommonExceptions.CheckStringEmpty(name, nameof(name));
     Contract.EndContractBlock();
     this.name = name;
     Init(targetType, nonPublic);
 }
Esempio n. 5
0
 /// <summary>
 /// 使用包含属性或字段的对象和名称,初始化 <see cref="MemberAccessor{T}"/> 类的新实例,
 /// 表示指定的实例属性或字段。
 /// </summary>
 /// <param name="target">包含实例属性或字段的对象。</param>
 /// <param name="name">属性或字段的名称。</param>
 /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(object target, string name)
 {
     CommonExceptions.CheckArgumentNull(target, nameof(target));
     CommonExceptions.CheckStringEmpty(name, nameof(name));
     Contract.EndContractBlock();
     this.name = name;
     Init(target, false);
 }
Esempio n. 6
0
 /// <summary>
 /// 使用包含静态属性或字段的类型和名称,初始化 <see cref="MemberAccessor{T}"/> 类的新实例,
 /// 表示指定的静态属性或字段。
 /// </summary>
 /// <param name="targetType">包含静态属性或字段的类型。</param>
 /// <param name="name">属性或字段的名称。</param>
 /// <exception cref="ArgumentNullException"><paramref name="targetType"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(Type targetType, string name)
 {
     CommonExceptions.CheckArgumentNull(targetType, "targetType");
     CommonExceptions.CheckStringEmpty(name, "name");
     Contract.EndContractBlock();
     this.name = name;
     this.Init(targetType, false);
 }
Esempio n. 7
0
 /// <summary>
 /// 使用包含属性或字段的对象和名称,初始化 <see cref="MemberAccessor{T}"/> 类的新实例,
 /// 表示指定的实例属性或字段。
 /// </summary>
 /// <param name="target">包含实例属性或字段的对象。</param>
 /// <param name="name">属性或字段的名称。</param>
 /// <param name="nonPublic">指示是否应访问非公共属性或字段。
 /// 如果要访问非公共属性或字段,则为 <c>true</c>;否则为 <c>false</c>。</param>
 /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentException"><paramref name="name"/> 为 <c>null</c> 或空字符串。</exception>
 public MemberAccessor(object target, string name, bool nonPublic)
 {
     CommonExceptions.CheckArgumentNull(target, "target");
     CommonExceptions.CheckStringEmpty(name, "name");
     Contract.EndContractBlock();
     this.name = name;
     this.Init(target, nonPublic);
 }
Esempio n. 8
0
        /// <summary>
        /// 创建指定对象中与标识指定相关的实例方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="target">在其中查找实例方法的对象。</param>
        /// <param name="id">处理器的标识。</param>
        /// <returns><paramref name="target"/> 中与指定标识相关的实例方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="target"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> 为空字符串。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(object target, string id)
            where TDelegate : class
        {
            CommonExceptions.CheckArgumentNull(target, nameof(target));
            CommonExceptions.CheckStringEmpty(id, nameof(id));
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            var data = GetMethods <TDelegate>(target.GetType(), id, false);

            return(CreateSwitcher <TDelegate>(data, id, target));
        }
Esempio n. 9
0
        /// <summary>
        /// 创建指定类型中与标识指定相关的静态方法切换器,会自动推断关键参数(使用不同子类的参数,必须是唯一的)。
        /// </summary>
        /// <typeparam name="TDelegate">使用基类型调用方法的委托。</typeparam>
        /// <param name="type">在其中查找静态方法的类型。</param>
        /// <param name="id">处理器的标识。</param>
        /// <returns><paramref name="type"/> 中与指定标识相关的静态方法切换器。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> 为空字符串。</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TDelegate"/> 不是委托类型。</exception>
        /// <exception cref="ArgumentException">委托类型与处理器不匹配。</exception>
        /// <exception cref="ArgumentException">处理器的参数不匹配。</exception>
        /// <exception cref="ArgumentException">没有找到唯一的关键参数。</exception>
        public static TDelegate Create <TDelegate>(Type type, string id)
            where TDelegate : class
        {
            CommonExceptions.CheckArgumentNull(type, "type");
            CommonExceptions.CheckStringEmpty(id, "id");
            Contract.Ensures(Contract.Result <TDelegate>() != null);
            CommonExceptions.CheckDelegateType(typeof(TDelegate));
            ProcessorData data = GetMethods <TDelegate>(type, id, true);

            return(CreateSwitcher <TDelegate>(data, id, null));
        }
Esempio n. 10
0
 /// <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;
 }
Esempio n. 11
0
 /// <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;
 }
Esempio n. 12
0
 /// <summary>
 /// 使用指定的标识符初始化 <see cref="ProcessorAttribute"/> 类的新实例。
 /// </summary>
 /// <param name="id">处理器的标识符。</param>
 /// <exception cref="ArgumentException"><paramref name="id"/> 为 <c>null</c> 或空字符串。</exception>
 public ProcessorAttribute(string id)
 {
     CommonExceptions.CheckStringEmpty(id, "id");
     Contract.EndContractBlock();
     this.id = id;
 }