ArgumentMustBeArray() статический приватный Метод

ArgumentException with message like "Argument must be array"
static private ArgumentMustBeArray ( string paramName ) : Exception
paramName string
Результат System.Exception
Пример #1
0
        /// <summary>
        /// Creates an <see cref="IndexExpression"></see> to access an array.
        /// </summary>
        /// <param name="array">An expression representing the array to index.</param>
        /// <param name="indexes">An <see cref="IEnumerable{Expression}"/> containing expressions used to index the array.</param>
        /// <remarks>The expression representing the array can be obtained by using the MakeMemberAccess method,
        /// or through NewArrayBounds or NewArrayInit.</remarks>
        /// <returns>The created <see cref="IndexExpression"/>.</returns>
        public static IndexExpression ArrayAccess(Expression array, IEnumerable <Expression> indexes)
        {
            RequiresCanRead(array, "array");

            var arrayType = array.Type;

            if (!arrayType.IsArray)
            {
                throw Error.ArgumentMustBeArray();
            }

            var indexList = indexes.ToReadOnly();

            if (arrayType.GetArrayRank() != indexList.Count)
            {
                throw Error.IncorrectNumberOfIndexes();
            }

            foreach (var e in indexList)
            {
                RequiresCanRead(e, "indexes");
                if (e.Type != typeof(int))
                {
                    throw Error.ArgumentMustBeArrayIndexType();
                }
            }

            return(new IndexExpression(array, null, indexList));
        }
Пример #2
0
        /// <summary>
        /// Creates an <see cref="IndexExpression"/> to access an array.
        /// </summary>
        /// <param name="array">An expression representing the array to index.</param>
        /// <param name="indexes">An <see cref="IEnumerable{T}"/> containing expressions used to index the array.</param>
        /// <remarks>The expression representing the array can be obtained by using the <see cref="MakeMemberAccess"/> method,
        /// or through <see cref="NewArrayBounds(Type, IEnumerable{Expression})"/> or <see cref="NewArrayInit(Type, IEnumerable{Expression})"/>.</remarks>
        /// <returns>The created <see cref="IndexExpression"/>.</returns>
        public static IndexExpression ArrayAccess(Expression array, IEnumerable <Expression>?indexes)
        {
            ExpressionUtils.RequiresCanRead(array, nameof(array));

            Type arrayType = array.Type;

            if (!arrayType.IsArray)
            {
                throw Error.ArgumentMustBeArray(nameof(array));
            }

            ReadOnlyCollection <Expression> indexList = indexes.ToReadOnly();

            if (arrayType.GetArrayRank() != indexList.Count)
            {
                throw Error.IncorrectNumberOfIndexes();
            }

            foreach (Expression e in indexList)
            {
                ExpressionUtils.RequiresCanRead(e, nameof(indexes));
                if (e.Type != typeof(int))
                {
                    throw Error.ArgumentMustBeArrayIndexType(nameof(indexes));
                }
            }

            return(new IndexExpression(array, null, indexList));
        }
Пример #3
0
        public static ConditionalArrayIndexCSharpExpression ConditionalArrayIndex(Expression array, IEnumerable <Expression> indexes)
        {
            RequiresCanRead(array, nameof(array));
            ContractUtils.RequiresNotNull(indexes, nameof(indexes));

            if (!array.Type.IsArray)
            {
                throw LinqError.ArgumentMustBeArray();
            }

            var indexList = indexes.ToReadOnly();

            if (array.Type.GetArrayRank() != indexList.Count)
            {
                throw LinqError.IncorrectNumberOfIndexes();
            }

            foreach (var index in indexList)
            {
                RequiresCanRead(index, "indexes");

                if (index.Type != typeof(int))
                {
                    throw LinqError.ArgumentMustBeArrayIndexType();
                }
            }

            return(new ConditionalArrayIndexCSharpExpression(array, indexList));
        }
Пример #4
0
        /// <summary>
        /// Creates an <see cref="IndexExpression"/> to access an array.
        /// </summary>
        /// <param name="array">An expression representing the array to index.</param>
        /// <param name="indexes">An <see cref="IEnumerable{T}"/> containing expressions used to index the array.</param>
        /// <remarks>The expression representing the array can be obtained by using the <see cref="MakeMemberAccess"/> method,
        /// or through <see cref="NewArrayBounds"/> or <see cref="NewArrayInit"/>.</remarks>
        /// <returns>The created <see cref="IndexExpression"/>.</returns>
        public static IndexExpression ArrayAccess(Expression array, IEnumerable <Expression> indexes)
        {
            ExpressionUtils.RequiresCanRead(array, nameof(array));

            var arrayType = array.Type;

            if (!arrayType.IsArray)
            {
                throw Error.ArgumentMustBeArray(nameof(array));
            }

            var indexList = Theraot.Collections.Extensions.AsArray(indexes);

            if (arrayType.GetArrayRank() != indexList.Length)
            {
                throw Error.IncorrectNumberOfIndexes();
            }

            foreach (var e in indexList)
            {
                ExpressionUtils.RequiresCanRead(e, nameof(indexes));
                if (e.Type != typeof(int))
                {
                    throw Error.ArgumentMustBeArrayIndexType(nameof(indexes));
                }
            }

            return(new IndexExpression(array, null, indexList));
        }
Пример #5
0
        //CONFORMING
        public static MethodCallExpression ArrayIndex(Expression array, IEnumerable <Expression> indexes)
        {
            RequiresCanRead(array, "array");
            ContractUtils.RequiresNotNull(indexes, "indexes");

            Type arrayType = array.Type;

            if (!arrayType.IsArray)
            {
                throw Error.ArgumentMustBeArray();
            }

            ReadOnlyCollection <Expression> indexList = indexes.ToReadOnly();

            if (arrayType.GetArrayRank() != indexList.Count)
            {
                throw Error.IncorrectNumberOfIndexes();
            }

            foreach (Expression e in indexList)
            {
                RequiresCanRead(e, "indexes");
                if (e.Type != typeof(int))
                {
                    throw Error.ArgumentMustBeArrayIndexType();
                }
            }

            MethodInfo mi = array.Type.GetMethod("Get", BindingFlags.Public | BindingFlags.Instance);

            return(Call(array, mi, indexList));
        }
Пример #6
0
 //CONFORMING
 public static UnaryExpression ArrayLength(Expression array)
 {
     ContractUtils.RequiresNotNull(array, "array");
     if (!array.Type.IsArray || !typeof(Array).IsAssignableFrom(array.Type))
     {
         throw Error.ArgumentMustBeArray();
     }
     if (array.Type.GetArrayRank() != 1)
     {
         throw Error.ArgumentMustBeSingleDimensionalArrayType();
     }
     return(new UnaryExpression(ExpressionType.ArrayLength, array, typeof(int), null));
 }
Пример #7
0
        /// <summary>
        /// Creates an expression representing an array access operation.
        /// </summary>
        /// <param name="array">The array to access.</param>
        /// <param name="indexes">The indexes used to access the array.</param>
        /// <returns>A new <see cref="ArrayAccessCSharpExpression"/> instance representing the array access operation.</returns>
        public static new ArrayAccessCSharpExpression ArrayAccess(Expression array, IEnumerable <Expression> indexes)
        {
            RequiresCanRead(array, nameof(array));

            var arrayType = array.Type;

            if (!arrayType.IsArray)
            {
                throw LinqError.ArgumentMustBeArray();
            }

            var indexesList = indexes.ToReadOnly();

            if (arrayType.GetArrayRank() != indexesList.Count)
            {
                throw LinqError.IncorrectNumberOfIndexes();
            }

            foreach (var index in indexesList)
            {
                RequiresCanRead(index, nameof(indexes));
            }

            if (indexesList.Count == 1)
            {
                var index = indexesList[0];

                if (index.Type == typeof(Index) || index.Type == typeof(Range))
                {
                    return(new ArrayAccessCSharpExpression(array, indexesList));
                }
            }

            foreach (var index in indexesList)
            {
                if (index.Type != typeof(int))
                {
                    throw LinqError.ArgumentMustBeArrayIndexType();
                }
            }

            return(new ArrayAccessCSharpExpression(array, indexesList));
        }