public static NewMultidimensionalArrayInitCSharpExpression NewMultidimensionalArrayInit(Type type, IEnumerable <int> bounds, IEnumerable <Expression> initializers) { ContractUtils.RequiresNotNull(type, nameof(type)); ContractUtils.RequiresNotNull(bounds, nameof(bounds)); ContractUtils.RequiresNotNull(initializers, nameof(initializers)); if (type.Equals(typeof(void))) { throw LinqError.ArgumentCannotBeOfTypeVoid(); } var boundsList = bounds.ToReadOnly(); int dimensions = boundsList.Count; if (dimensions <= 0) { throw LinqError.BoundsCannotBeLessThanOne(); } var length = 1; foreach (var bound in boundsList) { if (bound < 0) { throw Error.BoundCannotBeLessThanZero(); } checked { length *= bound; } } var initializerList = initializers.ToReadOnly(); if (initializerList.Count != length) { throw Error.ArrayBoundsElementCountMismatch(); } var newList = default(Expression[]); for (int i = 0, n = initializerList.Count; i < n; i++) { var expr = initializerList[i]; RequiresCanRead(expr, nameof(initializers)); if (!TypeUtils.AreReferenceAssignable(type, expr.Type)) { if (!TryQuote(type, ref expr)) { throw LinqError.ExpressionTypeCannotInitializeArrayType(expr.Type, type); } if (newList == null) { newList = new Expression[initializerList.Count]; for (int j = 0; j < i; j++) { newList[j] = initializerList[j]; } } } if (newList != null) { newList[i] = expr; } } if (newList != null) { initializerList = new TrueReadOnlyCollection <Expression>(newList); } return(new NewMultidimensionalArrayInitCSharpExpression(type.MakeArrayType(boundsList.Count), boundsList, initializerList)); }