Пример #1
0
        /// <summary>
        /// 获取新的代理类。
        /// </summary>
        /// <param name="objectType"></param>
        /// <returns></returns>
        public static Type GetProxyType(Type objectType)
        {
            Guard.ArgumentNull(objectType, nameof(objectType));

            if (objectType.IsSealed)
            {
                throw new AspectException(SR.GetString(SRKind.AopTypeMustNotSeald, objectType.FullName));
            }

            return(InterceptBuilder.BuildTypeCached(objectType));
        }
Пример #2
0
        /// <summary>
        /// 创建一个代理,将定义的拦截器注入到属性或方法内。
        /// </summary>
        /// <param name="objectType">用于创建代理类型的基类型。</param>
        /// <param name="args">创建对象的一组参数。</param>
        /// <returns></returns>
        public static object BuildProxy(Type objectType, params object[] args)
        {
            Guard.ArgumentNull(objectType, "objectType");

            if (objectType.IsSealed)
            {
                throw new AspectException(SR.GetString(SRKind.AopTypeMustNotSeald, objectType.FullName));
            }

            var proxyType = InterceptBuilder.BuildTypeCached(objectType);

            return(proxyType.InternalNew(args));
        }