本文整理汇总了C#中IMethodInvocation.CreateMethodReturn方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodInvocation.CreateMethodReturn方法的具体用法?C# IMethodInvocation.CreateMethodReturn怎么用?C# IMethodInvocation.CreateMethodReturn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethodInvocation
的用法示例。
在下文中一共展示了IMethodInvocation.CreateMethodReturn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
if (input.MethodBase.Name == "DoNothing")
{
return input.CreateMethodReturn(100);
}
if (input.MethodBase.Name == "DoNothing1")
{
return input.CreateMethodReturn(200);
}
return getNext()(input, getNext);
}
示例2: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (TargetMethodReturnsVoid(input))
{
return getNext()(input, getNext);
}
object[] inputs = new object[input.Inputs.Count];
for (int i = 0; i < inputs.Length; ++i)
{
inputs[i] = input.Inputs[i];
}
string cacheKey = KeyGenerator.CreateCacheKey(input.MethodBase, inputs);
object[] cachedResult = (object[])HttpRuntime.Cache.Get(cacheKey);
if (cachedResult == null)
{
IMethodReturn realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
AddToCache(cacheKey, realReturn.ReturnValue);
}
return realReturn;
}
IMethodReturn cachedReturn = input.CreateMethodReturn(cachedResult[0], input.Arguments);
return cachedReturn;
}
示例3: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (TargetMethodReturnsVoid(input))
{
return getNext()(input, getNext);
}
var inputs = new object[input.Inputs.Count];
for (var i = 0; i < inputs.Length; ++i)
{
inputs[i] = input.Inputs[i];
}
var cacheKey = keyGenerator.CreateCacheKey(input.MethodBase, inputs);
var cachedResult = MemoryCache.Default.Get(cacheKey);
if (cachedResult == null)
{
var realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
AddToCache(cacheKey, realReturn.ReturnValue);
}
return realReturn;
}
var cachedReturn = input.CreateMethodReturn(cachedResult, input.Arguments);
return cachedReturn;
}
示例4: 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);
}
示例5: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IUnityContainer container = UnityContainer;
Type targetType = null;
object result = null;
var logData =
String.Format("ThreadLocalDependencyInjector input: {0}, input.MethodBase: {1} ", input, input.MethodBase);
if (input.MethodBase is MethodInfo)
{
targetType = ((MethodInfo)input.MethodBase).ReturnType;
}
else
{
throw new DependencyResolutionException(String.Format("Can't apply TransientDependency injector to {0}. It could be applied only to methods.", input.MethodBase.Name));
}
try
{
result = container.Resolve(targetType);
}
catch (Exception e)
{
_logger.Info(String.Format("ThreadLocalDependencyInjector input data: {0}", logData));
throw new DependencyResolutionException(String.Format("Unable to resolve transient dependency of type {0}. See inner exception for details", targetType.FullName), e);
}
return input.CreateMethodReturn(result);
}
示例6: InvokeINotifyPropertyChangedMethod
private IMethodReturn InvokeINotifyPropertyChangedMethod(IMethodInvocation input)
{
if (input.MethodBase.DeclaringType == typeof(INotifyPropertyChanged))
{
switch (input.MethodBase.Name)
{
case "add_PropertyChanged":
lock (handlerLock)
{
handler = (PropertyChangedEventHandler)Delegate.Combine(handler, (Delegate)input.Arguments[0]);
}
break;
case "remove_PropertyChanged":
lock (handlerLock)
{
handler = (PropertyChangedEventHandler)Delegate.Remove(handler, (Delegate)input.Arguments[0]);
}
break;
default:
return input.CreateExceptionMethodReturn(new InvalidOperationException());
}
return input.CreateMethodReturn(null);
}
return null;
}
示例7: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (this.targetMethodReturnsVoid(input) == true)
{
return (getNext()(input, getNext));
}
Object [] inputs = new Object [ input.Inputs.Count ];
for (Int32 i = 0; i < inputs.Length; ++i)
{
inputs [ i ] = input.Inputs [ i ];
}
String cacheKey = this.createCacheKey(input.MethodBase, inputs);
ObjectCache cache = MemoryCache.Default;
Object [] cachedResult = (Object []) cache.Get(cacheKey);
if (cachedResult == null)
{
IMethodReturn realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
this.addToCache(cacheKey, realReturn.ReturnValue);
}
return (realReturn);
}
IMethodReturn cachedReturn = input.CreateMethodReturn(cachedResult [ 0 ], input.Arguments);
return (cachedReturn);
}
示例8: GetProperResponseTypeForMethodToReturn
protected IMethodReturn GetProperResponseTypeForMethodToReturn(IMethodInvocation input, string message)
{
Type retType = (input.MethodBase as MethodInfo).ReturnType;
object createdInstance = Activator.CreateInstance(retType);
createdInstance.GetType().GetProperty("Error").SetValue(createdInstance, message, null);
createdInstance.GetType().GetProperty("IsSuccess").SetValue(createdInstance, false, null);
IMethodReturn retu = input.CreateMethodReturn(createdInstance, input.Arguments);
return retu;
}
示例9: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
string key = (string)input.Inputs[0];
if (key == shortcutKey)
{
IMethodReturn result = input.CreateMethodReturn(-1);
return result;
}
return getNext()(input, getNext);
}
示例10: Invoke
/// <summary>
/// Returns previously cached response or invokes method and caches response
/// </summary>
/// <param name="input"></param>
/// <param name="getNext"></param>
/// <returns></returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
//if caching is disabled, leave:
if (!CacheConfiguration.Current.Enabled)
{
return Proceed(input, getNext);
}
//get the cache settings from the attribute & config:
var cacheAttribute = GetCacheSettings(input);
if (cacheAttribute.Disabled)
{
return Proceed(input, getNext);
}
//if there's no cache provider, leave:
var cache = Caching.Cache.Get(cacheAttribute.CacheType);
var serializer = Serializer.GetCurrent(cacheAttribute.SerializationFormat);
if (cache == null || cache.CacheType == CacheType.Null || serializer == null)
{
return Proceed(input, getNext);
}
var targetCategory = InstrumentCacheRequest(input);
var returnType = ((MethodInfo)input.MethodBase).ReturnType;
var cacheKey = CacheKeyBuilder.GetCacheKey(input, serializer);
var cachedValue = cache.Get(returnType, cacheKey, cacheAttribute.SerializationFormat);
if (cachedValue == null)
{
InstrumentCacheMiss(targetCategory, input);
//call the intended method to set the return value
var methodReturn = Proceed(input, getNext);
//only cache if we have a real return value & no exception:
if (methodReturn != null && methodReturn.ReturnValue != null && methodReturn.Exception == null)
{
var lifespan = cacheAttribute.Lifespan;
if (lifespan.TotalSeconds > 0)
{
cache.Set(cacheKey, methodReturn.ReturnValue, lifespan, cacheAttribute.SerializationFormat);
}
else
{
cache.Set(cacheKey, methodReturn.ReturnValue, cacheAttribute.SerializationFormat);
}
}
return methodReturn;
}
else
{
InstrumentCacheHit(targetCategory, input);
}
return input.CreateMethodReturn(cachedValue);
}
示例11: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (((input.MethodBase as MethodInfo).ReturnType != typeof(void)) || (this.Times == 1))
{
return (getNext()(input, getNext));
}
else
{
Parallel.For(0, this.Times, i => getNext()(input, getNext));
return (input.CreateMethodReturn(null));
}
}
示例12: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
UserName = GetUserNameFromInputs(input.Inputs);
//Authenticate user
if (!UserName.Equals("jbavari"))
{
throw new AuthenticationException("You aren't an authenticated user. Quit trying to leech our data.");
}
var toReturn = getNext()(input, getNext);
var actualReturn = input.CreateMethodReturn(toReturn.ReturnValue, input.Arguments);
return actualReturn;
}
示例13: Invoke
public IMethodReturn Invoke(
IMethodInvocation input,
GetNextInterceptionBehaviorDelegate getNext)
{
var result = getNext()(input, getNext);
if (result.Exception is CommunicationException
|| result.Exception is
InvalidOperationException)
{
this.AlertUser(result.Exception.Message);
return input.CreateMethodReturn(null);
}
return result;
}
示例14: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn result = null;
if ((input.MethodBase as MethodInfo).ReturnType == typeof(void))
{
result = input.CreateMethodReturn(null);
}
else
{
result = getNext()(input, getNext);
}
return (result);
}
示例15: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Boolean isSetter = input.MethodBase.Name.StartsWith("set_") == true;
IMethodReturn result = null;
if (isSetter != true)
{
result = getNext()(input, getNext);
}
else
{
result = input.CreateMethodReturn(null);
}
return (result);
}