Пример #1
0
        /// <inheritdoc/>
        public object AdaptProxy(Type interfaceType, object proxy)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException(String.Format(Resources.TypeNotAnInterfaceType, interfaceType), "interfaceType");
            }

            var instance     = _proxyDefinition.UnwrapProxy(proxy);
            var instanceType = instance.GetType();

            if ((instanceType != _implementationType) || !interfaceType.IsAssignableFrom(instanceType))
            {
                throw new InvalidOperationException(Resources.CannotAdaptProxy);
            }

            return(instance);
        }
Пример #2
0
        public object AdaptProxy(Type interfaceType, object proxy)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            if (!interfaceType.IsInterface)
            {
                throw new ArgumentException("类型{0}不是一个接口".FormatEx(interfaceType), "interfaceType");
            }

            var instance     = _proxyDefinition.UnwrapProxy(proxy);
            var instanceType = instance.GetType();

            if ((instanceType != _implementationType) || !interfaceType.IsAssignableFrom(instanceType))
            {
                throw new InvalidOperationException("这个接口类型不合适代理");
            }

            return(instance);
        }