예제 #1
0
 public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications)
 {
     if (_defaultChecker.IsDefault(argument, parameterInfo.ParameterType))
     {
         if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType))
         {
             var argumentSpecification = suppliedArgumentSpecifications.Dequeue();
             if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0)
             {
                 return(argumentSpecification);
             }
         }
         else if (!suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType))
         {
             if (suppliedArgumentSpecifications.DequeueRemaining().Count() == 0)
             {
                 return(_argumentEqualsSpecificationFactory.Create(argument, parameterInfo.ParameterType));
             }
         }
     }
     else
     {
         var paramterInfosFromParamsArray = _parameterInfosFromParamsArrayFactory.Create(argument, parameterInfo.ParameterType);
         var suppliedArgumentSpecificationsFromParamsArray = _suppliedArgumentSpecificationsFactory.Create(suppliedArgumentSpecifications.DequeueRemaining());
         var arrayArgumentSpecifications = _arrayArgumentSpecificationsFactory.Create(argument, paramterInfosFromParamsArray, suppliedArgumentSpecificationsFromParamsArray);
         return(_arrayContentsArgumentSpecificationFactory.Create(arrayArgumentSpecifications, parameterInfo.ParameterType));
     }
     throw new AmbiguousArgumentsException();
 }
        public IArgumentSpecification Create(object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications)
        {
            // Next specificaion is for the whole params array.
            if (suppliedArgumentSpecifications.IsNextFor(argument, parameterInfo.ParameterType))
            {
                return(suppliedArgumentSpecifications.Dequeue());
            }

            // Check whether the specification ambiguity could happen.
            bool isAmbiguousSpecificationPresent = suppliedArgumentSpecifications.AnyFor(argument, parameterInfo.ParameterType);

            if (isAmbiguousSpecificationPresent)
            {
                throw new AmbiguousArgumentsException(suppliedArgumentSpecifications.AllSpecifications);
            }

            // User passed "null" as the params array value.
            if (argument == null)
            {
                return(_argumentEqualsSpecificationFactory.Create(null, parameterInfo.ParameterType));
            }

            // User specified arguments using the native params syntax.
            var paramterInfosFromParamsArray = _parameterInfosFromParamsArrayFactory.Create(argument, parameterInfo.ParameterType);
            var arrayArgumentSpecifications  = _arrayArgumentSpecificationsFactory.Create(argument, paramterInfosFromParamsArray, suppliedArgumentSpecifications);

            return(_arrayContentsArgumentSpecificationFactory.Create(arrayArgumentSpecifications, parameterInfo.ParameterType));
        }