• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IInvocation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IInvocation的典型用法代码示例。如果您正苦于以下问题:C# IInvocation类的具体用法?C# IInvocation怎么用?C# IInvocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IInvocation类属于命名空间,在下文中一共展示了IInvocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CacheInvocation

        /// <summary>
        /// Caches the invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        /// <param name="cacheKeyProvider">The cache key provider.</param>
        /// <param name="cacheItemSerializer">The cache item serializer.</param>
        /// <param name="cacheStorageMode">The cache storage mode.</param>
        private void CacheInvocation(IInvocation invocation, ICacheKeyProvider cacheKeyProvider, ICacheItemSerializer cacheItemSerializer)
        {
            string hash = cacheKeyProvider.GetCacheKeyForMethod(invocation.InvocationTarget,
                invocation.MethodInvocationTarget, invocation.Arguments);

            string hashedObjectDataType = string.Format(HASHED_DATA_TYPE_FORMAT, hash);

            var cacheProvider = CacheProviderFactory.Default.GetCacheProvider();

            Type type = cacheProvider[hashedObjectDataType] as Type;
            object data = null;
            if (type != null && cacheProvider[hash] != null)
                data = cacheItemSerializer.Deserialize(cacheProvider[hash].ToString(), type,
                    invocation.InvocationTarget, invocation.Method, invocation.Arguments);

            if (data == null)
            {
                invocation.Proceed();
                data = invocation.ReturnValue;
                if (data != null)
                {
                    cacheProvider.Add(hashedObjectDataType, invocation.Method.ReturnType);
                    cacheProvider.Add(hash, cacheItemSerializer.Serialize(data, invocation.InvocationTarget,
                        invocation.Method, invocation.Arguments));
                }
            }
            else
                invocation.ReturnValue = data;
        }
开发者ID:eallegretta,项目名称:LtaBlog,代码行数:36,代码来源:CachingInterceptor.cs


示例2: Intercept

        public void Intercept(IInvocation invocation)
        {
            switch (invocation.Method.Name)
              {
            case "Close":
              _closedSubscribers(invocation.InvocationTarget, EventArgs.Empty);
              _closedSubscribers = delegate { };
              break;
            case "add_Closed":
              {
            var propertyChangedEventHandler = (EventHandler) invocation.Arguments[0];
            _closedSubscribers += propertyChangedEventHandler;
              }
              break;
            case "remove_Closed":
              {
            var propertyChangedEventHandler = (EventHandler) invocation.Arguments[0];
            _closedSubscribers -= propertyChangedEventHandler;
              }
              break;
              }

              if (invocation.TargetType != null)
            invocation.Proceed();
        }
开发者ID:leloulight,项目名称:magicgrove,代码行数:25,代码来源:CloseInterceptor.cs


示例3: Intercept

        public override void Intercept(IInvocation invocation)
        {
            // WPF will call a method named add_PropertyChanged to subscribe itself to the property changed events of
            // the given entity. The method to call is stored in invocation.Arguments[0]. We get this and add it to the
            // proxy subscriber list.
            if (invocation.Method.Name.Contains("PropertyChanged"))
            {
                PropertyChangedEventHandler propertyChangedEventHandler = (PropertyChangedEventHandler)invocation.Arguments[0];
                if (invocation.Method.Name.StartsWith("add_"))
                {
                    subscribers += propertyChangedEventHandler;
                }
                else
                {
                    subscribers -= propertyChangedEventHandler;
                }
            }

            // Here we call the actual method of the entity
            base.Intercept(invocation);

            // If the method that was called was actually a proeprty setter (set_Line1 for example) we generate the
            // PropertyChanged event for the property but with event generator the proxy. This must do the trick.
            if (invocation.Method.Name.StartsWith("set_"))
            {
                subscribers(invocation.InvocationTarget, new PropertyChangedEventArgs(invocation.Method.Name.Substring(4)));
            }
        }
开发者ID:MatiasBjorling,项目名称:EcoLoad,代码行数:28,代码来源:DataBindingIntercepter.cs


示例4: getKey

 private string getKey(IInvocation invocation, CacheAttribute attribute)
 {
     if (attribute.IsKey)
     {
         if (attribute.IsResolve)
         {
             throw new NotSupportedException();
         }
         else
         {
             return attribute.Key;
         }
     }
     else//if (attribute.IsArg)
     {
         if (attribute.IsResolve)
         {
             throw new NotSupportedException();
         }
         else
         {
             object[] args = InterceptorHelper.GetInvocationMethodArgs(invocation);
             if (attribute.Arg <= args.Length)
             {
                 return args[attribute.Arg].ToString();
             }
             else
             {
                 throw new IndexOutOfRangeException();
             }
         }
     }
 }
开发者ID:hitechie,项目名称:IocCore,代码行数:33,代码来源:CacheInterceptor.cs


示例5: Intercept

        public void Intercept(IInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.InvocationTarget, AbpCrossCuttingConcerns.Auditing))
            {
                invocation.Proceed();
                return;
            }

            if (!_auditingHelper.ShouldSaveAudit(invocation.MethodInvocationTarget))
            {
                invocation.Proceed();
                return;
            }

            var auditInfo = _auditingHelper.CreateAuditInfo(invocation.MethodInvocationTarget, invocation.Arguments);

            if (AsyncHelper.IsAsyncMethod(invocation.Method))
            {
                PerformAsyncAuditing(invocation, auditInfo);
            }
            else
            {
                PerformSyncAuditing(invocation, auditInfo);
            }
        }
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:25,代码来源:AuditingInterceptor.cs


示例6: OnException

        protected override void OnException(IInvocation invocation)
        {
            ExceptionContext arg;
            arg = invocation.Arguments[0] as ExceptionContext;
            var args = string.Join(",", arg.RouteData.Values.Select(x => x.Key + " = " + x.Value));
            string message = arg.Exception.Message;
            if(arg.Exception.InnerException != null)
            {
                message = message +" "+ arg.Exception.InnerException.Message;
            }

            if (arg.Exception.GetType() ==  typeof(DbEntityValidationException))
            {
                DbEntityValidationException dbEx = arg.Exception as DbEntityValidationException;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        message = message + "," + string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

            message = message + arg.Exception.StackTrace;
            _logger.Fatal(createRecord("Exception"
                            , arg.Controller.GetType().Name
                            , arg.Result.ToString()
                            , args
                            , message));
        }
开发者ID:AleksanderGalkin,项目名称:MyBlog,代码行数:30,代码来源:LogInterceptor.cs


示例7: Intercept

        public void Intercept(IInvocation invocation)
        {

            ICommand cmd = invocation.Arguments[0] as ICommand;
            ExecutedCommand executedCommand;
            if (cmd == null)
            {
               
                invocation.Proceed();
            }
            else
            {
                //this is a method that accepts a command invoker, should be intercepted
                 executedCommand = new ExecutedCommand()
                {
                    Command = cmd,
                    Id = cmd.Id,
                };
                try
                {
                    invocation.Proceed();
                    _commandStore.Store(executedCommand);
                }
                catch (Exception ex)
                {
                    executedCommand.IsSuccess = false;
                    executedCommand.Error = ex.ToString();
                    _commandStore.Store(executedCommand);
                    throw;
                }

            }


        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:35,代码来源:CommandStoreInterceptor.cs


示例8: Intercept

		public void Intercept(IInvocation invocation)
		{
			if (invocation.Method.ReturnType.IsValueType)
			{
				invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);
			}
		}
开发者ID:vbedegi,项目名称:Castle.InversionOfControl,代码行数:7,代码来源:ReturnDefaultInterceptor.cs


示例9: Intercept

        public void Intercept(IInvocation invocation)
        {
            foreach (var matchVsReturnValue in _invocationVersusReturnValue)
            {
                if (matchVsReturnValue.Key.Matches(invocation.Method, invocation.Arguments))
                {
                    invocation.ReturnValue = matchVsReturnValue.Value.Produce(invocation.Arguments);
                    return;
                }
            }

            if (Fallback != null)
            {
                invocation.ReturnValue = invocation.Method.Invoke(Fallback, invocation.Arguments);
            }
            else
            {
                if (invocation.Method.ReturnType != typeof(void))
                {
                    if (invocation.Method.ReturnType.IsValueType)
                        invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);
                    else
                        invocation.ReturnValue = null;
                }
            }
        }
开发者ID:ToshB,项目名称:nservicestub,代码行数:26,代码来源:WcfCallsInterceptor.cs


示例10: OnError

        protected override void OnError(IInvocation invocation, Exception exception)
        {
            string sw = string.Format("********** {0} **********\n Message: {1}", DateTime.Now, exception.Message);
            if (exception.InnerException != null)
            {
                sw += string.Format(
                    "Inner Exception Type: {0} \n Inner Exception: {1} \n Inner Source: {2}",
                    exception.InnerException.GetType(),
                    exception.InnerException.Message,
                    exception.InnerException.Source);
                if (exception.InnerException.StackTrace != null)
                {
                    sw += string.Format("\n Inner Stack Trace: {0}", exception.InnerException.StackTrace);
                }
            }
            sw += string.Format(
                "\n Exception Type: {0}\n Exception: {1}\n Source: {2}\n Stack Trace: ",
                exception.GetType(),
                exception.Message,
                MethodNameFor(invocation));
            if (exception.StackTrace != null)
            {
                sw += (exception.StackTrace);
            }

            this._logger.Error(
                exception, "There was an error invoking {0} Error details is:{1}.\r\n", MethodNameFor(invocation), sw);

            this._hasError = true;
            base.OnError(invocation, exception);
        }
开发者ID:jzinedine,项目名称:Cedar,代码行数:31,代码来源:LoggingInterceptor.cs


示例11: Intercept

        public void Intercept(IInvocation invocation)
        {
            string methodName = invocation.Method.Name;

            // if target method is property getter and return value is null - do interception.
            if (!methodName.StartsWith(PropertyGetMethodPefix) || invocation.ReturnValue != null)
            {
                return;
            }

            // logic here for illustration purpose only and should be moved to separate service.
            if (methodName.StartsWith(PropertyGetMethodPefix))
            {
                object value = null;
                string propertyName = methodName.Substring(PropertyGetMethodPefix.Count());

                PropertyInfo propertyInfo = invocation.TargetType.GetProperty(propertyName);
                var defaultValueAttr = (DefaultValueAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(DefaultValueAttribute));
                if (defaultValueAttr != null)
                {
                    var defaultValue = defaultValueAttr.Value;
                    if (defaultValue != null && invocation.Method.ReturnType.IsInstanceOfType(defaultValue))
                    {
                        value = defaultValue;
                    }
                }

                invocation.ReturnValue = value;
            }
        }
开发者ID:Romanets,项目名称:EPiInterceptors,代码行数:30,代码来源:DefaultPropertyValueInterceptor.cs


示例12: AfterInvoke

 protected override void AfterInvoke(IInvocation invocation)
 {
     this._logger.Info(
         "{0} finished {1}.",
         MethodNameFor(invocation),
         (this._hasError ? "with an error state" : "successfully"));
 }
开发者ID:jzinedine,项目名称:Cedar,代码行数:7,代码来源:LoggingInterceptor.cs


示例13: PreProceed

        public void PreProceed(IInvocation invocation)
        {
            Console.WriteLine("before action executed");

            int indent = 0;

            if (indent > 0)
            {
                Console.Write(" ".PadRight(indent * 4, ' '));
            }

            indent++;

            Console.Write("Intercepting: " + invocation.Method.Name + "(");

            if (invocation.Arguments != null && invocation.Arguments.Length > 0)
            {
                for (int i = 0; i < invocation.Arguments.Length; i++)
                {
                    if (i != 0) Console.Write(", ");
                    Console.Write(invocation.Arguments[i] == null
                        ? "null"
                        : invocation.Arguments[i].GetType() == typeof(string)
                           ? "\"" + invocation.Arguments[i].ToString() + "\""
                           : invocation.Arguments[i].ToString());
                }
            }

            Console.WriteLine(")");
        }
开发者ID:HK-Zhang,项目名称:Grains,代码行数:30,代码来源:CastleDynamicProxy.cs


示例14: Intercept

        public void Intercept(IInvocation invocation)
        {
            var methodName = invocation.Method.Name;
            var arguments = invocation.Arguments;
            var proxy = invocation.Proxy;
            var isEditableObject = proxy is IEditableObject;

            if (invocation.Method.DeclaringType.Equals(typeof (INotifyPropertyChanged)))
            {
                if (methodName == "add_PropertyChanged")
                {
                    StoreHandler((Delegate) arguments[0]);
                }
                if (methodName == "remove_PropertyChanged")
                {
                    RemoveHandler((Delegate) arguments[0]);
                }
            }

            if (!ShouldProceedWithInvocation(methodName))
                return;

            invocation.Proceed();

            NotifyPropertyChanged(methodName, proxy, isEditableObject);
        }
开发者ID:kkozmic,项目名称:Castle-Windsor-Examples,代码行数:26,代码来源:NotifyPropertyChangedBehavior.cs


示例15: PreProcess

        public virtual void PreProcess(IInvocation invocation, CoreInterceptContext context)
        {
            if (invocation.Method.Name.StartsWith("get_") || "ToString".Equals(invocation.Method.Name))
                return;

            context.ActionListener.ActionPerforming((UIItem)context.UiItem);
        }
开发者ID:huangzhichong,项目名称:White,代码行数:7,代码来源:ScrollInterceptor.cs


示例16: PerformUow

        private static void PerformUow(IInvocation invocation, bool isTransactional)
        {
            using (var unitOfWork = IocHelper.ResolveAsDisposable<IUnitOfWork>())
            {
                try
                {
                    UnitOfWorkScope.Current = unitOfWork.Object;
                    UnitOfWorkScope.Current.Initialize(isTransactional);
                    UnitOfWorkScope.Current.Begin();

                    try
                    {
                        invocation.Proceed();
                        UnitOfWorkScope.Current.End();
                    }
                    catch
                    {
                        try { UnitOfWorkScope.Current.Cancel(); } catch { } //Hide exceptions on cancelling
                        throw;
                    }
                }
                finally
                {
                    UnitOfWorkScope.Current = null;
                }
            }
        }
开发者ID:hersilio,项目名称:aspnetboilerplate,代码行数:27,代码来源:UnitOfWorkInterceptor.cs


示例17: Intercept

        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            var interceptors = Configuration.Interceptors;
            var orderedInterceptors = SortOrderFactory.GetSortOrderStrategy(invocation, interceptors).Sort();
            var validInterceptors = (from interceptor in orderedInterceptors
                                    where Interception.DoesTargetMethodHaveAttribute(invocation, interceptor.TargetAttributeType)
                                    select ResolveHowToCreateInterceptor(interceptor).Create(interceptor)).ToList();

            // 2012.05.14 -tyler brinks - Apparently it is no longer necessary with the new version of Castle to do
            // the "false" interceptions unless they exist without a valid interceptor.
            var falseInvocations = orderedInterceptors.Count() - validInterceptors.Count();

            if (falseInvocations > 0 /*&& validInterceptors.Count == 0*/)
            {
                for (var i = 0; i < falseInvocations; i++)
                {
                    // Not all interceptors run for each type, but all interceptors are interrogated.
                    // If there are 5 interceptors, but only 1 attribute, this handles the other 4
                    // necessary invocations.
                    invocation.Proceed();
                }
            }

            foreach (var interceptor in validInterceptors)
            {
                interceptor.BeforeInvocation();
                interceptor.Intercept(invocation);
                interceptor.AfterInvocation();
            }

            if (ResetPseudoInterceptors != null)
            {
                ResetPseudoInterceptors();
            }
        }
开发者ID:nickspoons,项目名称:Snap,代码行数:39,代码来源:MasterProxy.cs


示例18: Intercept

        public override void Intercept(IInvocation invocation)
        {
            try {
                invocation.Proceed();
            } catch (Exception eOnInvocation) {
                
                if (Preferences.Log) {
//                    try {
                        if (invocation.TargetType.IsSubclassOf(typeof(UiaCommand))) {
                            
                            AutomationFactory.GetLogHelper(string.Empty).Error(eOnInvocation.Message);
//                            var cmdlet =
//                                (invocation.InvocationTarget as UiaCommand).Cmdlet;
//                            var logger =
//                                AutomationFactory.GetLogger();
//                            logger.LogCmdlet(cmdlet);
                        }
//                    }
//                    catch (Exception eLoggingAspect) {
//                        // Console.WriteLine(eLoggingAspect.Message);
//                    }
                }
                
                var eNewException =
                    new Exception("Class " + invocation.TargetType.Name + ", method " + invocation.Method.Name + ": " + eOnInvocation.Message);
                throw eNewException;
            }
            
        }
开发者ID:apetrovskiy,项目名称:STUPS,代码行数:29,代码来源:ErrorHandlingAspect.cs


示例19: ConstraintsExpectation

 /// <summary>
 /// Creates a new <see cref="ConstraintsExpectation"/> instance.
 /// </summary>
 /// <param name="invocation">Invocation for this expectation</param>
 /// <param name="constraints">Constraints.</param>
 /// <param name="expectedRange">Number of method calls for this expectations</param>
 public ConstraintsExpectation(IInvocation invocation,AbstractConstraint[] constraints, Range expectedRange)
     : base(invocation, expectedRange)
 {
     Validate.IsNotNull(()=>constraints);
     this.constraints = constraints;
     ConstraintsMatchMethod();
 }
开发者ID:sneal,项目名称:rhino-mocks,代码行数:13,代码来源:ConstraintsExpectation.cs


示例20: Intercept

        public void Intercept(IInvocation invocation)
        {
            // let the original call go 1st
            invocation.Proceed();

            // make sure target is setting a property
            if (!invocation.Method.Name.StartsWith("set_")) return;

            var propertyName = invocation.Method.Name.Substring(4);
            var pi = invocation.TargetType.GetProperty(propertyName);

            // check for the [ObservableProperty] attribute
            if (!pi.HasAttribute<ObservablePropertyAttribute>()) return;

            // get reflected info of interception target
            var info = invocation.TargetType.GetFields(
                BindingFlags.Instance | BindingFlags.NonPublic)
                .FirstOrDefault(f => f.FieldType == typeof(PropertyChangedEventHandler));

            if (info != null)
            {
                //get the INPC field, and invoke it if we managed to get it ok
                var evHandler =
                    info.GetValue(invocation.InvocationTarget) as PropertyChangedEventHandler;
                if (evHandler != null)
                    evHandler.Invoke(invocation.InvocationTarget,
                                     new PropertyChangedEventArgs(propertyName));
            }
        }
开发者ID:AdamNThompson,项目名称:Duplex,代码行数:29,代码来源:ObservablePropertyInterceptor.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IInvocationInfo类代码示例发布时间:2022-05-24
下一篇:
C# IInventoryService类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap