本文整理汇总了C#中IMethodInvocation类的典型用法代码示例。如果您正苦于以下问题:C# IMethodInvocation类的具体用法?C# IMethodInvocation怎么用?C# IMethodInvocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMethodInvocation类属于命名空间,在下文中一共展示了IMethodInvocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var stopwatch = new Stopwatch();
var logger = LogManager.GetLogger(input.MethodBase.ReflectedType);
var declaringType = input.MethodBase.DeclaringType;
var className = declaringType != null ? declaringType.Name : string.Empty;
var methodName = input.MethodBase.Name;
var generic = declaringType != null && declaringType.IsGenericType
? string.Format("<{0}>", string.Join<Type>(", ", declaringType.GetGenericArguments()))
: string.Empty;
var argumentWriter = new List<string>();
for (var i = 0; i < input.Arguments.Count; i++)
{
var argument = input.Arguments[i];
var argumentInfo = input.Arguments.GetParameterInfo(i);
argumentWriter.Add(argumentInfo.Name);
}
var methodCall = string.Format("{0}{1}.{2}\n{3}", className, generic, methodName, string.Join(",", argumentWriter));
logger.InfoFormat(@"Entering {0}", methodCall);
stopwatch.Start();
var returnMessage = getNext()(input, getNext);
stopwatch.Stop();
logger.InfoFormat(@"Exited {0} after {1}ms", methodName, stopwatch.ElapsedMilliseconds);
return returnMessage;
}
示例2: Invoke
public object Invoke(IMethodInvocation invocation)
{
Log("Intercepted call : about to invoke method '{0}'", invocation.Method.Name);
object returnValue = invocation.Proceed();
Log("Intercepted call : returned '{0}'", returnValue);
return returnValue;
}
示例3: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.WriteLine($"Called: {input.Target.GetType()}.{input.MethodBase.Name}");
if (input.Arguments.Count > 0)
{
Console.WriteLine("\tWith Arguments");
for (var i = 0; i < input.Arguments.Count; i++)
{
Console.WriteLine($"\tName: {input.Arguments.GetParameterInfo(i)}");
}
}
var handlerDelegate = getNext();
Console.WriteLine("Execute...");
var methodReturn = handlerDelegate(input, getNext);
var result = methodReturn.ReturnValue?.ToString() ?? "(void)";
if (methodReturn.Exception != null)
{
Console.WriteLine($"Exception: {methodReturn.Exception}");
}
Console.WriteLine($"Result: {result}");
return methodReturn;
}
示例4: Invoke
public object Invoke(IMethodInvocation invocation)
{
LOG.Debug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
object returnValue = invocation.Proceed();
LOG.Debug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
return returnValue;
}
示例5: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var cacheAttr = GetAttribute(input);
if (cacheAttr == null) return getNext()(input, getNext);
string cacheKey = GetCacheKey(cacheAttr, input);
ICache cacheHandler = CacheProxy.GetCacheHandler(cacheAttr.CacheMode);
switch (cacheAttr.CacheType)
{
case CacheType.Fetch:
if (cacheHandler.Contain(cacheAttr.Group, cacheKey))
{
return input.CreateMethodReturn(cacheHandler.Get(cacheAttr.Group, cacheKey));
}
else
{
var r = getNext()(input, getNext);
cacheHandler.Add(cacheAttr.Group, cacheKey, r.ReturnValue);
return r;
}
case CacheType.Clear:
cacheHandler.Remove(cacheAttr.Group, cacheKey);
return getNext()(input, getNext);
}
return getNext()(input, getNext);
}
示例6: GetValueKey
/// <summary>
/// 根据指定的<see cref="CachingAttribute"/>以及<see cref="IMethodInvocation"/>实例,
/// 获取与某一特定参数值相关的键名。
/// </summary>
/// <param name="cachingAttribute"><see cref="CachingAttribute"/>实例。</param>
/// <param name="input"><see cref="IMethodInvocation"/>实例。</param>
/// <returns>与某一特定参数值相关的键名。</returns>
private string GetValueKey(CachingAttribute cachingAttribute, IMethodInvocation input)
{
switch (cachingAttribute.Method)
{
// 如果是Remove,则不存在特定值键名,所有的以该方法名称相关的缓存都需要清除
case CachingMethod.Remove:
return null;
// 如果是Get或者Put,则需要产生一个针对特定参数值的键名
case CachingMethod.Get:
case CachingMethod.Put:
if (input.Arguments != null &&
input.Arguments.Count > 0)
{
var sb = new StringBuilder();
for (int i = 0; i < input.Arguments.Count; i++)
{
sb.Append(input.Arguments[i].ToString());
if (i != input.Arguments.Count - 1)
sb.Append("_");
}
return sb.ToString();
}
else
return "NULL";
default:
throw new InvalidOperationException("无效的缓存方式。");
}
}
示例7: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
this.log.Debug("Before call to: {0}.{1}, parameters: {2}",
input.Target,
input.MethodBase.Name,
this.GetParameters(input));
var result = getNext()(input, getNext);
if (result.Exception != null)
{
this.log.Error("Exception while calling: {0}, parameters: {1}, ex: {2}",
input.MethodBase.Name,
this.GetParameters(input),
result.Exception);
}
else
{
this.log.Debug("Call finished: {0}, parameters: {1}, result: {2}",
input.MethodBase.Name,
this.GetParameters(input),
result.ReturnValue);
}
return result;
}
示例8: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
IMethodReturn result = null;
if (input.MethodBase.IsDefined(typeof(RequiresTransactionAttribute), true))
{
try
{
transactionManager.OpenTransaction();
this.transactionManager.Connection.QueryFileKey = this.context.GetQueryFile();
this.FindAndInjectDataAccessProperties(input);
result = getNext().Invoke(input, getNext);
if (result.Exception != null){
throw result.Exception;
}
transactionManager.Commit();
}
catch (Exception)
{
transactionManager.Rollback();
throw;
}
finally
{
transactionManager.Release();
}
}
else
{
result = getNext().Invoke(input, getNext); //proceed
}
return result;
}
示例9: Invoke
/// <exception cref="SapphireUserFriendlyException"><c>SapphireUserFriendlyException</c>.</exception>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var result = getNext()(input, getNext);
if (result.Exception == null)
return result;
throw new SapphireUserFriendlyException();
}
示例10: Invoke
public object Invoke(IMethodInvocation invocation)
{
Console.WriteLine("Before {0} on {1}", invocation.Method.Name, invocation.Method.DeclaringType);
object returnVal = invocation.Proceed();
Console.WriteLine("After {0} on {1}", invocation.Method.Name, invocation.Method.DeclaringType);
return returnVal;
}
示例11: Invoke
/// <summary>
/// Invokes the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="getNext">The get next.</param>
/// <returns>The method return result.</returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
foreach (var argument in input.Arguments)
{
string target = argument as string;
if (string.IsNullOrEmpty(target))
{
continue;
}
if (Regex.Match(target, @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").Success)
{
continue;
}
ArgumentException argumentException = new ArgumentException("Invalid e-mail format", input.MethodBase.Name);
Log.Error("Argument exception", argumentException, this);
return input.CreateExceptionMethodReturn(argumentException);
}
return getNext()(input, getNext);
}
示例12: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input.Arguments.Count > 0)
{
var arguments = new Argument[input.Arguments.Count];
for (int i = 0; i < input.Arguments.Count; i++)
{
arguments[i] = new Argument
{
Name = input.Arguments.ParameterName(i),
Value = input.Arguments[i]
};
}
_tape.RecordRequest(arguments, input.MethodBase.ReflectedType, input.MethodBase.Name);
}
Console.WriteLine("> Intercepting " + input.MethodBase.Name);
Console.WriteLine("> Intercepting " + input.MethodBase.ReflectedType);
IMethodReturn methodReturn = getNext()(input, getNext);
Console.WriteLine("> Intercepted return value: " + methodReturn.ReturnValue.GetType().Name);
if (methodReturn.ReturnValue != null)
{
_tape.RecordResponse(methodReturn.ReturnValue, input.MethodBase.ReflectedType, input.MethodBase.Name);
}
return methodReturn;
}
示例13: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var methodName = input.MethodBase.Name;
var target = input.Target;
return getNext()(input, getNext);
}
示例14: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var className = input.Target.ToString().Split('.').Last();
var methodName = input.MethodBase.Name;
// Before invoking the method on the original target.
_log.Debug("{className}: {function} started.", className, methodName);
var timer = new Stopwatch();
timer.Start();
// Invoke the next behavior in the chain.
var result = getNext()(input, getNext);
timer.Stop();
// After invoking the method on the original target.
if (result.Exception != null)
{
_log.Warning("--- {className}: {function} threw exception {exception}.", className, methodName, result.Exception);
}
else
{
_log.Debug("--- {className}: {function} returned {returnValue}.", className, methodName, result);
}
_log.Information("--- {className}: {function} executed in {executionTime} (in Milliseconds).", className, methodName, timer.Elapsed.TotalMilliseconds);
return result;
}
示例15: Invoke
public object Invoke(IMethodInvocation invocation)
{
ConsoleLoggingAttribute[] consoleLoggingInfo =
(ConsoleLoggingAttribute[])invocation.Method.GetCustomAttributes(typeof(ConsoleLoggingAttribute), false);
if (consoleLoggingInfo.Length > 0)
{
Color = consoleLoggingInfo[0].Color;
}
ConsoleColor currentColor = Console.ForegroundColor;
Console.ForegroundColor = Color;
Console.Out.WriteLine(String.Format(
"Intercepted call : about to invoke method '{0}'", invocation.Method.Name));
Console.ForegroundColor = currentColor;
object returnValue = invocation.Proceed();
Console.ForegroundColor = Color;
Console.Out.WriteLine(String.Format(
"Intercepted call : returned '{0}'", returnValue));
Console.ForegroundColor = currentColor;
return returnValue;
}