diff --git a/ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs b/ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs index fdeed6ce9..9a33ae37e 100644 --- a/ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs +++ b/ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs @@ -120,25 +120,23 @@ namespace ICSharpCode.Decompiler.ILAst bool ForwardScanInitializeArrayRuntimeHelper(List<ILNode> body, int pos, ILVariable array, TypeReference arrayType, int arrayLength, out ILExpression[] values, out int foundPos) { - for (; pos < body.Count; pos++) { - ILVariable v2; - MethodReference methodRef; - ILExpression methodArg1; - ILExpression methodArg2; - FieldDefinition field; - if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) && - methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" && - methodRef.Name == "InitializeArray" && - methodArg1.Match(ILCode.Ldloc, out v2) && - array == v2 && - methodArg2.Match(ILCode.Ldtoken, out field) && - field != null && field.InitialValue != null) { - ILExpression[] newArr = new ILExpression[arrayLength]; - if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) { - values = newArr; - foundPos = pos; - return true; - } + ILVariable v2; + MethodReference methodRef; + ILExpression methodArg1; + ILExpression methodArg2; + FieldDefinition field; + if (body.ElementAtOrDefault(pos).Match(ILCode.Call, out methodRef, out methodArg1, out methodArg2) && + methodRef.DeclaringType.FullName == "System.Runtime.CompilerServices.RuntimeHelpers" && + methodRef.Name == "InitializeArray" && + methodArg1.Match(ILCode.Ldloc, out v2) && + array == v2 && + methodArg2.Match(ILCode.Ldtoken, out field) && + field != null && field.InitialValue != null) { + ILExpression[] newArr = new ILExpression[arrayLength]; + if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) { + values = newArr; + foundPos = pos; + return true; } } values = null; diff --git a/ICSharpCode.Decompiler/Tests/InitializerTests.cs b/ICSharpCode.Decompiler/Tests/InitializerTests.cs index 433a61c11..5fcee53b5 100644 --- a/ICSharpCode.Decompiler/Tests/InitializerTests.cs +++ b/ICSharpCode.Decompiler/Tests/InitializerTests.cs @@ -709,4 +709,86 @@ public class InitializerTests } }; } + + public void ArrayOfArrayOfArrayInit() + { + int[][,,] array = new int[][,,] + { + new int[, , ] + { + { + { + 1, + 2, + 3 + }, + { + 4, + 5, + 6 + }, + { + 7, + 8, + 9 + } + }, + { + { + 11, + 12, + 13 + }, + { + 14, + 15, + 16 + }, + { + 17, + 18, + 19 + } + } + }, + + new int[, , ] + { + { + { + 21, + 22, + 23 + }, + { + 24, + 25, + 26 + }, + { + 27, + 28, + 29 + } + }, + { + { + 31, + 32, + 33 + }, + { + 34, + 35, + 36 + }, + { + 37, + 38, + 39 + } + } + } + }; + } }