当前位置: 首页>>代码示例>>C#>>正文


C# IMethodInvocation.CreateMethodReturn方法代码示例

本文整理汇总了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);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:13,代码来源:InterceptedObjects.cs

示例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;
        }
开发者ID:huoxudong125,项目名称:WCF-Demo,代码行数:30,代码来源:CachingCallHandler.cs

示例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;
        }
开发者ID:Warrenn,项目名称:Carbon.MVC,代码行数:30,代码来源:CachingCallHandlerAttribute.cs

示例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);
        }
开发者ID:howbigbobo,项目名称:DailyCode,代码行数:27,代码来源:CacheCallHandler.cs

示例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);
        }
开发者ID:shichico,项目名称:hangfire,代码行数:27,代码来源:ThreadLocalDependencyInjector.cs

示例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;
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:29,代码来源:NaiveINotifyPropertyChangedInterceptionBehavior.cs

示例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);
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:34,代码来源:CacheAttribute.cs

示例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;
 }
开发者ID:jbavari,项目名称:WCF-Unity,代码行数:9,代码来源:CallHandlerBase.cs

示例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);
 }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:10,代码来源:ShortcuttingHandler.cs

示例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);
        }
开发者ID:Narinyir,项目名称:caching,代码行数:59,代码来源:CacheCallHandler.cs

示例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));
			}
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:13,代码来源:ParallelizeAttribute.cs

示例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;
        }
开发者ID:jbavari,项目名称:WCF-Unity,代码行数:14,代码来源:AuthenticationCallHandler.cs

示例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;
 }
开发者ID:mesta1,项目名称:dli.net_sourcecode,代码行数:14,代码来源:ErrorHandlingInterceptionBehavior.cs

示例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);
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:15,代码来源:NoOpAttribute.cs

示例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);
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:16,代码来源:ReadOnlyAttribute.cs


注:本文中的IMethodInvocation.CreateMethodReturn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。