コード例 #1
0
        private static NewInstancePredicate NewInstance(TypeUsage instanceType, IEnumerable <Predicate> arguments)
        {
            PredicateList validArguments;
            var           expectedTypes        = GetStructuralMemberTypes(instanceType);
            var           pos                  = 0;
            bool          allowEmpty           = false;
            var           validatedElements    = new List <Predicate>();
            int           expectedElementCount = expectedTypes.Count;
            bool          checkCount           = (expectedElementCount != -1);
            var           checkNull            = (default(Predicate) == null);

            foreach (var elementIn in arguments)
            {
                if (checkCount && pos == expectedElementCount)
                {
                    throw new ArgumentException();
                }

                if (checkNull && elementIn == null)
                {
                    throw new ArgumentNullException();
                }
                validatedElements.Add(elementIn);
                pos++;
            }
            if (checkCount)
            {
                if (pos != expectedElementCount)
                {
                    throw new ArgumentException();
                }
            }
            else
            {
                if (0 == pos && !allowEmpty)
                {
                    throw new ArgumentException();
                }
            }
            validArguments = new PredicateList(validatedElements);
            return(new NewInstancePredicate(instanceType, validArguments));
        }
コード例 #2
0
 internal NewInstancePredicate(TypeUsage type, PredicateList args)
     : base(PredicateType.NewInstance, type)
 {
     _elements = args;
 }