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; }
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; }
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; }
private static WebApiMethodAttribute GetWebApiMethodAttribute(InvocationInfo info) { var webApiMethodAttr = info.TargetMethod.GetCustomAttributes(typeof(WebApiMethodAttribute), true).FirstOrDefault() as WebApiMethodAttribute; return webApiMethodAttr; }
public object Intercept(InvocationInfo info) { var realTargetMethod = createGenericMethodInfoIfNeeded(info.TargetMethod, info.TypeArguments); return methodMarkedForCaching(realTargetMethod) ? interceptUsingCache(realTargetMethod, info.Arguments) : callOriginalMethod(realTargetMethod, info.Arguments); }
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); }
public override object Intercept(InvocationInfo info) { if (_members.ContainsKey(info.TargetMethod.Name)) { Debug.WriteLine("AAAA"); } return info.TargetMethod.Invoke(_target, info.Arguments); }
object LinFu.DynamicProxy.IInterceptor.Intercept( InvocationInfo info ) { IProxyRequest request = CreateRequest( info ); IInvocation invocation = CreateInvocation( request ); invocation.Proceed(); return invocation.ReturnValue; }
/*----------------------------------------------------------------------------------------*/ #region IInterceptor Implementation object IInterceptor.Intercept(InvocationInfo info) { IRequest request = CreateRequest(info); IInvocation invocation = CreateInvocation(request); invocation.Proceed(); return invocation.ReturnValue; }
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; }
/*----------------------------------------------------------------------------------------*/ #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); }
public object DoInvoke(InvocationInfo info) { if (IsAsyncMethod(info.TargetMethod)) { return PerformAsyncInvoke(info); } else { return PerformInvoke(info); } }
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; } }
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); }
public object Intercept(InvocationInfo info) { lock (_locker) { try { return info.TargetMethod.Invoke(_target, info.Arguments); } catch (TargetInvocationException ex) { throw ex.FindOriginalException().PrepareToRethrow(); } } }
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; }
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); }
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; }
public abstract object Intercept(InvocationInfo info);
/// <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(); } }
public object Intercept(InvocationInfo info) => DuckType(_request, info);
public void AfterInvoke(InvocationInfo info, object returnValue) { }
public void AfterInvoke(InvocationInfo info, object returnValue) { Console.WriteLine(info.TargetMethod.Name); }
private object PerformInvoke(InvocationInfo info) { var response = PerformWebApiCall(info).Result; return ReadResponseContent(info, response).Result; }
public LinFuInvocationAdapter(InvocationInfo invocation, object target) { this.invocation = invocation; this.target = target; }
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); }
public void BeforeInvoke(InvocationInfo info) { }
public object DoInvoke(InvocationInfo info) { return info.TargetMethod.Invoke(info.Target, info.Arguments); }
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); }
public ResponseCall(InvocationInfo info, Task<HttpResponseMessage> response) { _info = info; _response = response; }