public object Intercept(object instance, Type typeToIntercept, IInterceptionHandler handler)
		{
			if (instance == null)
			{
				throw (new ArgumentNullException("instance"));
			}

			if (typeToIntercept == null)
			{
				throw (new ArgumentNullException("typeToIntercept"));
			}

			if (handler == null)
			{
				throw (new ArgumentNullException("handler"));
			}

			if (this.CanIntercept(instance) == false)
			{
				throw (new ArgumentException("instance"));
			}

			if (typeToIntercept.IsInstanceOfType(instance) == false)
			{
				throw (new ArgumentException("typeToIntercept"));
			}

			var proxy = new TransparentProxy(this, instance, typeToIntercept, handler);

			return (proxy.GetTransparentProxy());
		}
		public object Intercept(object instance, Type typeToIntercept, IInterceptionHandler handler)
		{
			if (!(instance is ContextBoundObject))
			{
				throw new ArgumentException("Instance is not a ContextBoundObject.", "instance");
			}

			interceptors[instance as ContextBoundObject] = handler;

			return (instance);
		}
		public ConditionalInterceptionHandler(Func<InterceptionArgs, bool> condition, IInterceptionHandler handler)
		{
			if (condition == null)
			{
				throw new ArgumentNullException("condition");
			}

			if (handler == null)
			{
				throw new ArgumentNullException("handler");
			}

			this.condition = condition;
			this.handler = handler;
		}
		public DynamicProxy(IInterceptor interceptor, object target, IInterceptionHandler handler)
		{
			if (interceptor == null)
			{
				throw new ArgumentNullException("target");
			}

			if (target == null)
			{
				throw new ArgumentNullException("target");
			}

			if (handler == null)
			{
				throw new ArgumentNullException("handler");
			}

			this.Interceptor = interceptor;
			this.target = target;
			this.handler = handler;
		}
Пример #5
0
        public DynamicProxy(IInterceptor interceptor, object target, IInterceptionHandler handler)
        {
            if (interceptor == null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            this.Interceptor = interceptor;
            this.Target      = target;
            this.handler     = handler;
        }
		public object Intercept(object instance, Type typeToIntercept, IInterceptionHandler handler)
		{
			if (instance == null)
			{
				throw (new ArgumentNullException("instance"));
			}

			if (typeToIntercept == null)
			{
				throw (new ArgumentNullException("typeToIntercept"));
			}

			if (handler == null)
			{
				throw (new ArgumentNullException("handler"));
			}

			if (typeToIntercept.IsInstanceOfType(instance) == false)
			{
				throw (new ArgumentNullException("instance"));
			}

			if (typeToIntercept.IsInterface == false)
			{
				throw (new ArgumentNullException("typeToIntercept"));
			}

			if (this.CanIntercept(instance) == false)
			{
				throw (new ArgumentNullException("instance"));
			}

			var interfaceProxy = this.generator.Generate(this, typeof(InterfaceProxy), null, typeToIntercept);

			var newInstance = Activator.CreateInstance(interfaceProxy, this, handler, instance);

			return (newInstance);
		}
Пример #7
0
        public object Intercept(object target, Type typeToIntercept, IInterceptionHandler handler)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (typeToIntercept == null)
            {
                throw new ArgumentNullException(nameof(typeToIntercept));
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (typeToIntercept.IsInstanceOfType(target) == false)
            {
                throw new ArgumentException("Instance to intercept does not implement interception interface", nameof(target));
            }

            if (typeToIntercept.IsInterface == false)
            {
                throw new ArgumentException("Type to intercept is not an interface", nameof(typeToIntercept));
            }

            if (this.CanIntercept(target) == false)
            {
                throw new ArgumentException("Type to intercept cannot be intercepted with this interceptor", nameof(target));
            }

            var interfaceProxy = this.generator.Generate(this, typeof(InterfaceProxy), null, typeToIntercept);

            var newInstance = Activator.CreateInstance(interfaceProxy, this, handler, target);

            return(newInstance);
        }
		protected InterfaceProxy(IInterceptor interceptor, IInterceptionHandler handler, object instance)
		{
			this.instance = instance;
			this.interceptor = interceptor;
			this.handler = handler;
		}
 public static dynamic InterceptDynamic(this object instance, IInterceptionHandler handler)
 {
     return((dynamic)DynamicInterceptor.Instance.Intercept(instance, handler));
 }
		public TransparentProxy(TransparentProxyInterceptor interceptor, object instance, Type typeToIntercept, IInterceptionHandler handler) : base(typeToIntercept)
		{
			this.instance = instance;
			this.handler = handler;
			this.interceptor = interceptor;
		}