Ejemplo n.º 1
0
        public void TryGetItemTypeOfClosedGenericIEnumerable_ArgumentImplementsIEnumerable_BothGenericAndNonGeneric_ReturnsTrue()
        {
            Type itemType;
            var  result = ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(typeof(int[]), out itemType);

            Assert.That(result, Is.True);
            Assert.That(itemType, Is.SameAs(typeof(int)));
        }
Ejemplo n.º 2
0
        public void TryGetItemTypeOfClosedGenericIEnumerable_ArgumentImplementsIEnumerable_Generic_ReturnsFalse()
        {
            Type itemType;
            var  result = ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(typeof(GenericWithIEnumerable <int>), out itemType);

            Assert.That(result, Is.False);
            Assert.That(itemType, Is.Null);
        }
Ejemplo n.º 3
0
        public void TryGetItemTypeOfClosedGenericIEnumerable_ArgumentIsIEnumerable_ReturnsTrue()
        {
            Type itemType;
            var  result = ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(typeof(IEnumerable <IEnumerable <string> >), out itemType);

            Assert.That(result, Is.True);
            Assert.That(itemType, Is.SameAs(typeof(IEnumerable <string>)));
        }
Ejemplo n.º 4
0
        public void TryGetItemTypeOfClosedGenericIEnumerable_InvalidType_ReturnsFalse()
        {
            Type itemType;
            var  result = ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(typeof(int), out itemType);

            Assert.That(result, Is.False);
            Assert.That(itemType, Is.Null);
        }
Ejemplo n.º 5
0
        public void TryGetItemTypeOfClosedGenericIEnumerable_ArgumentIsArray_ReturnsTrue_Strange()
        {
            Expression <Func <int, IEnumerable <double> > > collectionSelector = x => new double[1];
            Type itemType;
            var  result = ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(collectionSelector.Body.Type, out itemType);

            Assert.That(result, Is.True);
            Assert.That(itemType, Is.SameAs(typeof(double)));
        }
        public ArrayGeneratingFunctionExpressionNode(MethodCallExpressionParseInfo parseInfo, Expression argument1)
        {
            QuerySourceType = parseInfo.ParsedExpression.Type;

            if (!ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(parseInfo.ParsedExpression.Type,
                                                                                    out _querySourceElementType))
            {
                _querySourceElementType = typeof(object);
            }

            ParsedExpression     = parseInfo.ParsedExpression;
            AssociatedIdentifier = parseInfo.AssociatedIdentifier;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the item type of closed generic i enumerable.
        /// </summary>
        private static Type GetItemTypeOfClosedGenericIEnumerable(Type enumerableType, string argumentName)
        {
            Type itemType;

            if (!ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(enumerableType, out itemType))
            {
                var message = string.Format("Expected a closed generic type implementing IEnumerable<T>, " +
                                            "but found '{0}'.", enumerableType);

                throw new ArgumentException(message, argumentName);
            }

            return(itemType);
        }
Ejemplo n.º 8
0
        public static Type GetItemTypeOfClosedGenericIEnumerable(Type enumerableType, string argumentName)
        {
            ArgumentUtility.CheckNotNull("enumerableType", enumerableType);
            ArgumentUtility.CheckNotNullOrEmpty("argumentName", argumentName);

            Type itemType;

            if (!ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(enumerableType, out itemType))
            {
                var message = string.Format("Expected a closed generic type implementing IEnumerable<T>, but found '{0}'.", enumerableType);
                throw new ArgumentException(message, argumentName);
            }

            return(itemType);
        }
        public MainSourceExpressionNode(string associatedIdentifier, Expression expression)
        {
            ArgumentUtility.CheckNotNullOrEmpty("associatedIdentifier", associatedIdentifier);
            ArgumentUtility.CheckNotNull("expression", expression);
            ArgumentUtility.CheckTypeIsAssignableFrom("expression.Type", expression.Type, typeof(IEnumerable));

            _querySourceType = expression.Type;

            if (!ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(expression.Type, out _querySourceElementType))
            {
                _querySourceElementType = typeof(object);
            }

            _associatedIdentifier = associatedIdentifier;
            _parsedExpression     = expression;
        }
Ejemplo n.º 10
0
        public static Type GetItemTypeOfClosedGenericIEnumerable(Type enumerableType, string argumentName)
        {
            if (enumerableType == null)
            {
                throw new ArgumentNullException(nameof(enumerableType));
            }

            if (string.IsNullOrEmpty(argumentName))
            {
                throw new ArgumentException("message", nameof(argumentName));
            }

            Type itemType;

            if (!ItemTypeReflectionUtility.TryGetItemTypeOfClosedGenericIEnumerable(enumerableType, out itemType))
            {
                var message = string.Format("Expected a closed generic type implementing IEnumerable<T>, but found '{0}'.", enumerableType);
                throw new ArgumentException(message, argumentName);
            }

            return(itemType);
        }