Exemple #1
0
        private ArrayInfo getArrayInfo(Type arrayType)
        {
            // Caching is innacceptable, as an array of type string can have different bounds

            var info = new ArrayInfo();

            // Fill the dimension infos
            for (int dimension = 0; dimension < getRank(arrayType); dimension++)
            {
                var dimensionInfo = new DimensionInfo();
                dimensionInfo.Length     = getLength(dimension, arrayType);
                dimensionInfo.LowerBound = getLowerBound(dimension, arrayType);
                info.DimensionInfos.Add(dimensionInfo);
            }


            return(info);
        }
Exemple #2
0
        ///<summary>
        ///</summary>
        ///<param name = "action"></param>
        public void ForEach(Action <int[]> action)
        {
            DimensionInfo dimensionInfo = _arrayInfo.DimensionInfos[0];

            for (int index = dimensionInfo.LowerBound; index < dimensionInfo.LowerBound + dimensionInfo.Length; index++)
            {
                var result = new List <int>();

                // Adding the first coordinate
                result.Add(index);

                if (_arrayInfo.DimensionInfos.Count < 2)
                {
                    // only one dimension
                    action.Invoke(result.ToArray());
                    continue;
                }

                // further dimensions
                forEach(_arrayInfo.DimensionInfos, 1, result, action);
            }
        }
Exemple #3
0
        /// <summary>
        ///   This functiona will be recursively used
        /// </summary>
        /// <param name = "dimensionInfos"></param>
        /// <param name = "dimension"></param>
        /// <param name = "coordinates"></param>
        /// <param name = "action"></param>
        private void forEach(IList <DimensionInfo> dimensionInfos, int dimension, IEnumerable <int> coordinates,
                             Action <int[]> action)
        {
            DimensionInfo dimensionInfo = dimensionInfos[dimension];

            for (int index = dimensionInfo.LowerBound; index < dimensionInfo.LowerBound + dimensionInfo.Length; index++)
            {
                var result = new List <int>(coordinates);

                // Adding the first coordinate
                result.Add(index);

                if (dimension == _arrayInfo.DimensionInfos.Count - 1)
                {
                    // This is the last dimension
                    action.Invoke(result.ToArray());
                    continue;
                }

                // Further dimensions
                forEach(_arrayInfo.DimensionInfos, dimension + 1, result, action);
            }
        }