コード例 #1
0
		public object Intercept(InvocationInfo info)
		{
			string methodName = info.TargetMethod.Name;
			if ("get_DataHandler".Equals(methodName))
			{
				return this;
			}
			else if (methodName.StartsWith("set_"))
			{
				string propertyName = methodName.Substring(4);
				data[propertyName] = info.Arguments[0];
			}
			else if (methodName.StartsWith("get_"))
			{
				string propertyName = methodName.Substring(4);
				return data[propertyName];
			}
			else if ("ToString".Equals(methodName))
			{
				return entityName + "#" + data["Id"];
			}
			else if ("GetHashCode".Equals(methodName))
			{
				return GetHashCode();
			}
			return null;
		}
コード例 #2
0
ファイル: XObjectInterceptor.cs プロジェクト: sdether/XObject
 public object Intercept(InvocationInfo info)
 {
     if(_doc == null) {
         throw new InvalidOperationException("Cannot use an XObjectInterceptor without an XDoc");
     }
     string methodName = info.TargetMethod.Name;
     if(methodName == "get_AsDocument") {
         RebuildDoc();
         return _doc;
     }
     if(methodName == "get_Item") {
         RebuildDoc();
         return _doc[info.Arguments[0].ToString()];
     }
     string accessor = methodName.Substring(4);
     InterceptionRecord record = _memberLookup[accessor];
     XDoc subdoc = _doc[record.XPath];
     object result;
     _backingFields.TryGetValue(accessor, out result);
     if(result == null) {
         result = record.Convert(subdoc);
         _backingFields[accessor] = result;
     }
     if(methodName.StartsWith("get_")) {
         return result;
     }
     _backingFields[accessor] = info.Arguments[0] ?? string.Empty;
     return null;
 }
コード例 #3
0
ファイル: Interceptor.cs プロジェクト: moq/moq.proxy
		public object Intercept (InvocationInfo invocation)
		{
			//ReturnValue = invocation.TargetMethod.Invoke (invocation.Target, invocation.Arguments);
			if (invocation.TargetMethod.DeclaringType == typeof (IProxy))
				return Behaviors;

			var input = new MethodInvocation(invocation.Target, invocation.TargetMethod, invocation.Arguments);
			var returns = pipeline.Invoke(input, (i, next) => {
				try {
					var returnValue = invocation.TargetMethod.Invoke (invocation.Target, invocation.Arguments);
					return input.CreateValueReturn(returnValue, invocation.Arguments);
				}
				catch (TargetInvocationException tie) {
					return input.CreateExceptionReturn(tie.InnerException);
				}
				catch (Exception ex) {
					return input.CreateExceptionReturn(ex);
				}
			});

			var exception = returns.Exception;
			if (exception != null)
				throw exception;

			for (int i = 0; i < returns.Outputs.Count; i++) {
				var name = returns.Outputs.GetName(i);
				var index = input.Arguments.IndexOf (name);
				invocation.SetArgument (index, returns.Outputs[index]);
			}

			return returns.ReturnValue;
		}
コード例 #4
0
 private static WebApiMethodAttribute GetWebApiMethodAttribute(InvocationInfo info)
 {
     var webApiMethodAttr =
         info.TargetMethod.GetCustomAttributes(typeof(WebApiMethodAttribute), true).FirstOrDefault() as
         WebApiMethodAttribute;
     return webApiMethodAttr;
 }
コード例 #5
0
ファイル: CacheInterceptor.cs プロジェクト: chenzuo/mbcache
		public object Intercept(InvocationInfo info)
		{
			var realTargetMethod = createGenericMethodInfoIfNeeded(info.TargetMethod, info.TypeArguments);
			return methodMarkedForCaching(realTargetMethod) ?
					  interceptUsingCache(realTargetMethod, info.Arguments) : 
					  callOriginalMethod(realTargetMethod, info.Arguments);
		}
コード例 #6
0
        public object Intercept(object proxy, MethodInfo targetMethod,
                                StackTrace trace, Type[] genericTypeArgs,
                                object[] args)
        {
            InvocationInfo info = new InvocationInfo(proxy, targetMethod, trace, genericTypeArgs, args);

            return Intercept(info);
        }
コード例 #7
0
 public override object Intercept(InvocationInfo info)
 {
     if (_members.ContainsKey(info.TargetMethod.Name))
     {
         Debug.WriteLine("AAAA");
     }
     return info.TargetMethod.Invoke(_target, info.Arguments);
 }
コード例 #8
0
        object LinFu.DynamicProxy.IInterceptor.Intercept( InvocationInfo info )
        {
            IProxyRequest request = CreateRequest( info );
            IInvocation invocation = CreateInvocation( request );

            invocation.Proceed();

            return invocation.ReturnValue;
        }
コード例 #9
0
ファイル: LinFuWrapper.cs プロジェクト: jamarlthomas/ninject1
		/*----------------------------------------------------------------------------------------*/
		#region IInterceptor Implementation
		object IInterceptor.Intercept(InvocationInfo info)
		{
			IRequest request = CreateRequest(info);
			IInvocation invocation = CreateInvocation(request);

			invocation.Proceed();

			return invocation.ReturnValue;
		}
コード例 #10
0
ファイル: Program.cs プロジェクト: abhipallav/asprofiled
 public object DoInvoke(InvocationInfo info)
 {
     Console.WriteLine("Wywołanie metody Do()");
     object result = null;
     // W celu wywołania oryginalnej metody Do() należy
     // usunąć komentarz z następnej linii:
     result = info.TargetMethod.Invoke(_target, info.Arguments);
     return result;
 }
コード例 #11
0
ファイル: LinFuWrapper.cs プロジェクト: jamarlthomas/ninject1
		/*----------------------------------------------------------------------------------------*/
		#region Private Methods
		private IRequest CreateRequest(InvocationInfo info)
		{
			var requestFactory = Context.Binding.Components.Get<IRequestFactory>();

			return requestFactory.Create(
				Context,
				Instance,
				info.TargetMethod,
				info.Arguments,
				info.TypeArguments);
		}
コード例 #12
0
        public object DoInvoke(InvocationInfo info)
        {
            if (IsAsyncMethod(info.TargetMethod))
            {
                return PerformAsyncInvoke(info);
            }
            else
            {

                return PerformInvoke(info);
            }
        }
コード例 #13
0
 object IInterceptor.Intercept(InvocationInfo info)
 {
     try
     {
         if (target == null)
             throw new NullReferenceException(string.Format("Target not set for {0} conduit, when method {1} was called from {2}", proxy.GetType(), info.TargetMethod, info.CallingMethod));
         return info.TargetMethod.Invoke(target, info.Arguments);
     }
     catch (TargetInvocationException ex)
     {
         throw ex.InnerException;
     }
 }
コード例 #14
0
        private static Task<object> ReadResponseContent(InvocationInfo info, HttpResponseMessage response)
        {
            if (!response.IsSuccessStatusCode)
                throw new Exception(response.ReasonPhrase);

            var webApiMethodAttr = GetWebApiMethodAttribute(info);

            var formatters = GlobalConfiguration.MediaTypeFormatters;

            if (webApiMethodAttr != null)
                formatters = new[] { Activator.CreateInstance(webApiMethodAttr.MediaTypeFormatter) as MediaTypeFormatter };

            return response.Content.ReadAsAsync(info.TargetMethod.ReturnType, formatters);
        }
コード例 #15
0
 public object Intercept(InvocationInfo info)
 {
     lock (_locker)
     {
         try
         {
             return info.TargetMethod.Invoke(_target, info.Arguments);
         }
         catch (TargetInvocationException ex)
         {
             throw ex.FindOriginalException().PrepareToRethrow();
         }
     }
 }
コード例 #16
0
        public object Intercept(InvocationInfo info)
        {
            object toReturn = null;

            if (IsSetterCall(info))
            {
                _propertyValues[GetPropertyName(info)] = info.Arguments[0];
            }
            else if (IsGetterCall(info))
            {
                toReturn = _propertyValues[GetPropertyName(info)];
            }

            return toReturn;
        }
コード例 #17
0
        public object Intercept(InvocationInfo info)
        {
            #region Sanity checks
            if (info == null) throw new ArgumentNullException(nameof(info));
            #endregion

            // Double-checked locking
            if (_context == null)
            {
                lock (_initLock)
                {
                    if (_context == null)
                        _context = InitExternalContext();
                }
            }

            _request.Debug("Forwarding to other Zero Install instance: {0}", info.TargetMethod.Name);
            return DuckType(_context, info);
        }
コード例 #18
0
ファイル: XObjectInterceptor.cs プロジェクト: danice/XObject
        public object Intercept(InvocationInfo info)
        {
            if(_doc == null) {
                throw new InvalidOperationException("Cannot use an XObjectInterceptor without an XDoc");
            }
            string methodName = info.TargetMethod.Name;
            if(methodName == "get_AsDocument") {
                RebuildDoc();
                return _doc;
            }
            if(methodName == "get_Item") {
                RebuildDoc();
                return _doc[info.Arguments[0].ToString()];
            }
            string accessor = methodName.Substring(4);
            InterceptionRecord record = _memberLookup[accessor];
            XDoc subdoc;
            string defxpath = null;
            if ((!_doc.IsEmpty)&&(!String.IsNullOrEmpty(_doc.Root.EmptyNamespaceUri))) {
                defxpath = XPathUtils.GetPrefixedPath(record.XPath, "_");
                subdoc = _doc[defxpath];
            } else {
                subdoc = _doc[record.XPath];
            }

            object result;
            _backingFields.TryGetValue(accessor, out result);
            if(result == null) {
                result = record.Convert(subdoc);
                _backingFields[accessor] = result;
            }
            if(methodName.StartsWith("get_")) {
                return result;
            }
            _backingFields[accessor] = info.Arguments[0] ?? string.Empty;
            return null;
        }
コード例 #19
0
 public abstract object Intercept(InvocationInfo info);
コード例 #20
0
        /// <summary>
        /// Forwards a method invocation <paramref name="info"/> to a <paramref name="target"/> using duck-typing.
        /// </summary>
        private static object DuckType(object target, InvocationInfo info)
        {
            var method = target.GetType().GetMethod(
                info.TargetMethod.Name,
                info.TargetMethod.GetParameters().Select(x => x.ParameterType).ToArray());
            if (method == null) throw new InvalidOperationException("Unable to find suitable method for duck-typing: " + info.TargetMethod.Name);

            try
            {
                return method.Invoke(target, info.Arguments);
            }
            catch (TargetInvocationException ex) when (ex.InnerException != null)
            {
                throw ex.InnerException.PreserveStack();
            }
        }
コード例 #21
0
 public object Intercept(InvocationInfo info) => DuckType(_request, info);
コード例 #22
0
 public void AfterInvoke(InvocationInfo info, object returnValue)
 {
 }
コード例 #23
0
ファイル: ProxyTests.cs プロジェクト: ruanzx/mausch
 public void AfterInvoke(InvocationInfo info, object returnValue)
 {
     Console.WriteLine(info.TargetMethod.Name);
 }
コード例 #24
0
        private object PerformInvoke(InvocationInfo info)
        {
            var response = PerformWebApiCall(info).Result;

            return ReadResponseContent(info, response).Result;
        }
コード例 #25
0
 public LinFuInvocationAdapter(InvocationInfo invocation, object target)
 {
     this.invocation = invocation;
     this.target = target;
 }
コード例 #26
0
        private Task<HttpResponseMessage> PerformWebApiCall(InvocationInfo info)
        {
            var webApiMethodAttr = GetWebApiMethodAttribute(info);

            if (webApiMethodAttr == null)
            {
                string httpMethod = "get";

                if (info.TargetMethod.Name.In(StringComparison.OrdinalIgnoreCase, "post", "put", "delete", "get"))
                {
                    httpMethod = info.TargetMethod.Name.ToLowerInvariant();
                }

                return GetWebApiResponse(info, httpMethod, info.TargetMethod.Name, new JsonMediaTypeFormatter());
            }

            var formatter = Activator.CreateInstance(webApiMethodAttr.MediaTypeFormatter) as MediaTypeFormatter;

            string uri = string.IsNullOrWhiteSpace(webApiMethodAttr.Uri)
                             ? info.TargetMethod.Name
                             : webApiMethodAttr.Uri;

            return GetWebApiResponse(info, webApiMethodAttr.HttpMethod, uri, formatter);
        }
コード例 #27
0
ファイル: ProxyTests.cs プロジェクト: ruanzx/mausch
 public void BeforeInvoke(InvocationInfo info)
 {
 }
コード例 #28
0
ファイル: ProxyTests.cs プロジェクト: ruanzx/mausch
 public object DoInvoke(InvocationInfo info)
 {
     return info.TargetMethod.Invoke(info.Target, info.Arguments);
 }
コード例 #29
0
        private HttpContent GetObjectContentFromArguments(InvocationInfo info, MediaTypeFormatter formatter = null)
        {
            if (formatter == null)
                formatter = GlobalConfiguration.MediaTypeFormatters.First();

            var data = new Dictionary<string, object>();

            for (int index = 0; index < info.TypeArguments.Length; index++)
            {
                data.Add(info.TypeArguments[index].Name, info.Arguments[index]);
            }

            return new ObjectContent<Dictionary<string, object>>(data, formatter);
        }
コード例 #30
0
 public ResponseCall(InvocationInfo info, Task<HttpResponseMessage> response)
 {
     _info = info;
     _response = response;
 }