|
|
|
@ -18,6 +18,7 @@
@@ -18,6 +18,7 @@
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Reflection; |
|
|
|
|
|
|
|
|
|
using ICSharpCode.Decompiler.CSharp.Syntax; |
|
|
|
|
using ICSharpCode.Decompiler.CSharp.Syntax.PatternMatching; |
|
|
|
@ -304,8 +305,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -304,8 +305,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
var metadata = context.TypeSystem.MainModule.PEFile.Metadata; |
|
|
|
|
SRM.MethodDefinition ctorMethodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)ctorMethod.MetadataToken); |
|
|
|
|
SRM.TypeDefinition declaringType = metadata.GetTypeDefinition(ctorMethodDef.GetDeclaringType()); |
|
|
|
|
if (declaringType.HasFlag(System.Reflection.TypeAttributes.BeforeFieldInit)) |
|
|
|
|
{ |
|
|
|
|
bool declaringTypeIsBeforeFieldInit = declaringType.HasFlag(TypeAttributes.BeforeFieldInit); |
|
|
|
|
while (true) |
|
|
|
|
{ |
|
|
|
|
ExpressionStatement es = staticCtor.Body.Statements.FirstOrDefault() as ExpressionStatement; |
|
|
|
@ -324,6 +324,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -324,6 +324,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
{ |
|
|
|
|
fieldOrPropertyDecl.Modifiers |= Modifiers.Unsafe; |
|
|
|
|
} |
|
|
|
|
// Only move fields that are constants, if the declaring type is not marked beforefieldinit.
|
|
|
|
|
if (declaringTypeIsBeforeFieldInit || fieldOrProperty is IField { IsConst: true }) |
|
|
|
|
{ |
|
|
|
|
if (fieldOrPropertyDecl is FieldDeclaration fd) |
|
|
|
|
fd.Variables.Single().Initializer = assignment.Right.Detach(); |
|
|
|
|
else if (fieldOrPropertyDecl is PropertyDeclaration pd) |
|
|
|
@ -332,7 +335,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
@@ -332,7 +335,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
|
|
|
|
|
break; |
|
|
|
|
es.Remove(); |
|
|
|
|
} |
|
|
|
|
if (staticCtor.Body.Statements.Count == 0) |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (declaringTypeIsBeforeFieldInit && staticCtor.Body.Statements.Count == 0) |
|
|
|
|
{ |
|
|
|
|
staticCtor.Remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|