Example #1
0
        /// <summary>
        /// 使用默认构造函数创建指定原型类型的属性更改通知类型的实例。
        /// </summary>
        /// <param name="baseType">原型类型,应为接口或非密封类。</param>
        /// <returns>一个不使用参数创建的属性更改通知类型的实例。</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="baseType"/> 为 <see langword="null"/>。</exception>
        /// <exception cref="MissingMethodException">
        /// <paramref name="baseType"/> 不包含无参构造函数。</exception>
        /// <exception cref="MethodAccessException">
        /// <paramref name="baseType"/> 的无参构造函数访问级别过低。</exception>
        public static object CreateObservable(Type baseType)
        {
            if (baseType is null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }
            var provider = ObservableTypeProvider.OfType(baseType);

            return(provider.CreateObservableInstance(Array.Empty <object>()));
        }
Example #2
0
        /// <summary>
        /// 使用与指定参数匹配程度最高的构造函数创建指定原型类型的属性更改通知类型的实例。
        /// </summary>
        /// <param name="baseType">原型类型,应为接口或非密封类。</param>
        /// <param name="arguments">与要调用构造函数的参数数量、顺序和类型匹配的参数数组。</param>
        /// <returns>一个使用指定参数创建的属性更改通知类型的实例。</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="baseType"/> 为 <see langword="null"/>。</exception>
        /// <exception cref="MissingMethodException"><paramref name="baseType"/>
        /// 不包含与 <paramref name="arguments"/> 相匹配的构造函数。</exception>
        /// <exception cref="MethodAccessException"><paramref name="baseType"/>
        /// 中与 <paramref name="arguments"/> 相匹配的构造函数的访问级别过低。</exception>
        public static object CreateObservable(Type baseType, params object?[]?arguments)
        {
            if (baseType is null)
            {
                throw new ArgumentNullException(nameof(baseType));
            }
            var provider = ObservableTypeProvider.OfType(baseType);

            return(provider.CreateObservableInstance(arguments));
        }
Example #3
0
 /// <summary>
 /// 初始化 <see cref="ObservableFactory{T}"/> 类的新实例。
 /// </summary>
 /// <exception cref="ArgumentException">
 /// <typeparamref name="T"/> 不是公共接口,也不是公共非密封类。</exception>
 private ObservableFactory()
 {
     this.TypeProvider = ObservableTypeProvider.OfType(typeof(T));
 }