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


C# IMethodInvocation.CreateExceptionMethodReturn方法代码示例

本文整理汇总了C#中IMethodInvocation.CreateExceptionMethodReturn方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodInvocation.CreateExceptionMethodReturn方法的具体用法?C# IMethodInvocation.CreateExceptionMethodReturn怎么用?C# IMethodInvocation.CreateExceptionMethodReturn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMethodInvocation的用法示例。


在下文中一共展示了IMethodInvocation.CreateExceptionMethodReturn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

		public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
		{
			Dictionary<Type, Validator> validators = new Dictionary<Type, Validator>();
			Int32 i = 0;
			ValidationResults results = new ValidationResults();
			IMethodReturn result = null;

			foreach (Type type in input.MethodBase.GetParameters().Select(p => p.ParameterType))
			{
				if (validators.ContainsKey(type) == false)
				{
					validators[type] = ValidationFactory.CreateValidator(type, this.Ruleset);
				}

				Validator validator = validators[type];
				validator.Validate(input.Arguments[i], results);

				++i;
			}

			if (results.IsValid == false)
			{
				result = input.CreateExceptionMethodReturn(new Exception(String.Join(Environment.NewLine, results.Select(r => r.Message).ToArray())));
			}
			else
			{
				result = getNext()(input, getNext);
			}

			return (result);
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:31,代码来源:ValidateAttribute.cs

示例2: Invoke

 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 {
     var results = input.Arguments.Cast<object>().SelectMany(entity => validator.Validate(entity));
     return !results.Any()
         ? getNext()(input, getNext) //no errors
         : input.CreateExceptionMethodReturn(new ValidationFailedException(results));
 }
开发者ID:tmont,项目名称:portoa,代码行数:7,代码来源:ValidationCallHandler.cs

示例3: 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

示例4: 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);
    }
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:31,代码来源:EmailValueAttribute.cs

示例5: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            var methodReturn = InvokeINotifyPropertyChangedMethod(input);

            if (methodReturn != null)
            {
                return methodReturn;
            }

            methodReturn = getNext()(input, getNext);

            if (methodReturn.Exception == null && input.MethodBase.IsSpecialName)
            {
                var property = GetPropertyInfoForSetMethod(input);

                if (property != null)
                {
                    var currentHandler = this.handler;
                    if (currentHandler != null)
                    {
                        try
                        {
                            currentHandler(input.Target, new PropertyChangedEventArgs(property.Name));
                        }
                        catch (Exception e)
                        {
                            return input.CreateExceptionMethodReturn(e);
                        }
                    }
                }
            }

            return methodReturn;
        }
开发者ID:jorgeds001,项目名称:CodeSamples,代码行数:34,代码来源:NaiveINotifyPropertyChangedInterceptionBehavior.cs

示例6: Invoke

        public IMethodReturn Invoke(
            IMethodInvocation input, 
            GetNextHandlerDelegate getNext)
        {
            if (this.allowedRoles.Length > 0)
            {
                IPrincipal currentPrincipal = Thread.CurrentPrincipal;

                if (currentPrincipal != null)
                {
                    bool allowed = false;
                    foreach (string role in this.allowedRoles)
                    {
                        if (allowed = currentPrincipal.IsInRole(role))
                        {
                            break;
                        }
                    }

                    if (!allowed)
                    {
                        // short circuit the call
                        return input.CreateExceptionMethodReturn(
                            new UnauthorizedAccessException(
                                "User not allowed to invoke the method"));
                    }
                }
            }

            return getNext()(input, getNext);
        }
开发者ID:kanpinar,项目名称:unity3.1th,代码行数:31,代码来源:AccessCheckCallHandler.cs

示例7: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            if (!this.IsValidUser())
            {
                return input.CreateExceptionMethodReturn(new UnauthorizedAccessException("..."));
            }

            return getNext()(input, getNext);
        }
开发者ID:bezysoftware,项目名称:presentations,代码行数:9,代码来源:AuthorizationInterceptionBehavior.cs

示例8: Invoke

 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 {
     User user = input.Inputs[0] as User;
     if (user.PassWord.Length < 0) {
         return input.CreateExceptionMethodReturn(new Exception("密码长度不能小于10位"));
     }
     Console.WriteLine("参数检测无误");
     return getNext()(input, getNext);
 }
开发者ID:wudan330260402,项目名称:Danwu.Core,代码行数:9,代码来源:UserHandler.cs

示例9: Invoke

        /// <summary>
        /// Handler de invocação do método com atributo
        /// </summary>
        /// <param name="input">Informações da chamada</param>
        /// <param name="getNext">Próximo handler de execução do método</param>
        /// <returns>Caso estejamos fora dum UoW, retorna exception, caso contrário segue a execução</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            if (UnitOfWork.Current == null)
            {
                return input.CreateExceptionMethodReturn(new Exception("Método " + input.MethodBase.Name + " chamado fora de UnitOfWork."));
            }

            // Retornamos normalmente
            return getNext()(input, getNext);
        }
开发者ID:lstern,项目名称:practices,代码行数:16,代码来源:RequiresUnitOfWorkAttribute.cs

示例10: Invoke

 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 {
     for (int i = 0; i < input.Inputs.Count; i++) {
         object target = input.Inputs[i];
         if (target == null) {
             ParameterInfo parameterInfo = input.Inputs.GetParameterInfo(i);
             ArgumentNullException ex = new ArgumentNullException(parameterInfo.Name);
             return input.CreateExceptionMethodReturn(ex);
         }
     }
     return getNext()(input, getNext);
 }
开发者ID:alexisjojo,项目名称:ktibiax,代码行数:12,代码来源:Temp.cs

示例11: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            if (input.Inputs.Count == 0) { return getNext()(input, getNext); }
            Order order = input.Inputs[0] as Order;
            if (order == null) { return getNext()(input, getNext); }
            if (order.OrderDate > DateTime.Today)
            {
                return input.CreateExceptionMethodReturn(new OrderValidationException("The order date is later than the current date!"));
            }

            if (order.Items.Count == 0)
            {
                return input.CreateExceptionMethodReturn(new OrderValidationException("There are not any items for the order!"));
            }

            if (this.ValidateSupplier)
            {
                if (!LegalSuppliers.Contains<string>(order.Supplier))
                {
                    return input.CreateExceptionMethodReturn(new OrderValidationException("The supplier is inllegal!"));
                }
            }

            if (this.ValidateTotalPrice)
            {
                double totalPrice = 0;
                foreach (OrderItem item in order.Items)
                {
                    totalPrice += item.Quantity * item.UnitPrice;
                }
                if (totalPrice != order.TotalPrice)
                {
                    return input.CreateExceptionMethodReturn(new OrderValidationException("The sum of the order item is not equal to the order total price!"));
                }
            }

            return getNext()(input, getNext);
        }
开发者ID:fr4nky80,项目名称:LearnCSharp,代码行数:38,代码来源:MyLogFrame.cs

示例12: Invoke

		public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
		{
			IMethodReturn result = null;

			if (Transaction.Current == null)
			{
				result = input.CreateExceptionMethodReturn(new Exception("Ambient transaction required"));
			}
			else
			{
				result = getNext()(input, getNext);
			}

			return (result);
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.UnityAop,代码行数:15,代码来源:RequireTransactionAttribute.cs

示例13: Invoke

        /// <summary>
        /// Performs the operation of the handler.
        /// </summary>
        /// <param name="input">Input to the method call.</param>
        /// <param name="getNext">Delegate used to get the next delegate in the call handler pipeline.</param>
        /// <returns>Returns value from the target method, or an <see cref="UnauthorizedAccessException"/>
        /// if the call fails the authorization check.</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            if (input == null) throw new ArgumentNullException("input");
            if (getNext == null) throw new ArgumentNullException("getNext");

            ReplacementFormatter formatter = new MethodInvocationFormatter(input);
            if (!this.AuthorizationProvider.Authorize(Thread.CurrentPrincipal, formatter.Format(OperationName)))
            {
                UnauthorizedAccessException unauthorizedExeption =
                    new UnauthorizedAccessException(Resources.AuthorizationFailed);
                return input.CreateExceptionMethodReturn(unauthorizedExeption);
            }

            return getNext().Invoke(input, getNext);
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:22,代码来源:AuthorizationCallHandler.cs

示例14: Invoke

 public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
 {
     try
     {
         using (TransactionScope transactionScope = new TransactionScope())
         {
             IMethodReturn methodReturn = getNext()(input, getNext);
             transactionScope.Complete();
             return methodReturn;
         }
     }
     catch (Exception ex)
     {
         return input.CreateExceptionMethodReturn(ex);
     }
 }
开发者ID:ittray,项目名称:LocalDemo,代码行数:16,代码来源:TransactionCallHandler.cs

示例15: Invoke

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            bool autenticado = true;
            autenticado = ControladorDeSessao.EstaAutenticado();

            if (autenticado)
            {
                IMethodReturn result = getNext()(input, getNext);
                return result;
            }
            else
            {
                // TODO: criar tratamento de erro para autenticacao
                return input.CreateExceptionMethodReturn(new ApplicationValidationErrorsException("Usuário não autenticado."));
            }
        }
开发者ID:MURYLO,项目名称:pegazuserp,代码行数:16,代码来源:AutenticacaoCallHandler.cs


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