Browse Source

Fix #211 InvalidCastException in ILAstOptimizer.TransformArrayInitializers

pull/252/head
Daniel Grunwald 15 years ago
parent
commit
17a75ded4e
  1. 13
      ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

13
ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

@ -124,21 +124,26 @@ namespace ICSharpCode.Decompiler.ILAst @@ -124,21 +124,26 @@ namespace ICSharpCode.Decompiler.ILAst
MethodReference methodRef;
ILExpression methodArg1;
ILExpression methodArg2;
FieldDefinition field;
FieldReference fieldRef;
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) {
methodArg2.Match(ILCode.Ldtoken, out fieldRef))
{
FieldDefinition fieldDef = fieldRef.ResolveWithinSameModule();
if (fieldDef != null && fieldDef.InitialValue != null) {
ILExpression[] newArr = new ILExpression[arrayLength];
if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()), field.InitialValue, newArr)) {
if (DecodeArrayInitializer(TypeAnalysis.GetTypeCode(arrayType.GetElementType()),
fieldDef.InitialValue, newArr))
{
values = newArr;
foundPos = pos;
return true;
}
}
}
values = null;
foundPos = -1;
return false;

Loading…
Cancel
Save