private object createObjectFromMultidimensionalArrayProperty(MultiDimensionalArrayProperty property) { // determine array type MultiDimensionalArrayCreatingInfo creatingInfo = getMultiDimensionalArrayCreatingInfo(property.DimensionInfos); // Instantiating the array Array array = createArrayInstance(property.ElementType, creatingInfo.Lengths, creatingInfo.LowerBounds); if (property.Reference != null) { // property has Reference, only objects referenced multiple times // have properties with references. Object must be cached to // resolve its references in the future. _objectCache.Add(property.Reference.Id, array); } // fill the values foreach (MultiDimensionalArrayItem item in property.Items) { object value = CreateObject(item.Value); if (value != null) { array.SetValue(value, item.Indexes); } } return(array); }
/// <summary> /// This internal class helps to instantiate the multidimensional array /// </summary> /// <param name = "infos"></param> /// <returns></returns> private static MultiDimensionalArrayCreatingInfo getMultiDimensionalArrayCreatingInfo( IEnumerable <DimensionInfo> infos) { var lengths = new List <int>(); var lowerBounds = new List <int>(); foreach (DimensionInfo info in infos) { lengths.Add(info.Length); lowerBounds.Add(info.LowerBound); } var result = new MultiDimensionalArrayCreatingInfo(); result.Lengths = lengths.ToArray(); result.LowerBounds = lowerBounds.ToArray(); return(result); }
/// <summary> /// This internal class helps to instantiate the multidimensional array /// </summary> /// <param name="infos"></param> /// <returns></returns> private static MultiDimensionalArrayCreatingInfo getMultiDimensionalArrayCreatingInfo( IEnumerable<DimensionInfo> infos) { var lengths = new List<int>(); var lowerBounds = new List<int>(); foreach (var info in infos) { lengths.Add(info.Length); lowerBounds.Add(info.LowerBound); } var result = new MultiDimensionalArrayCreatingInfo(); result.Lengths = lengths.ToArray(); result.LowerBounds = lowerBounds.ToArray(); return result; }