diff options
author | Jb Evain <jb@evain.net> | 2017-04-04 02:11:06 +0300 |
---|---|---|
committer | Jb Evain <jb@evain.net> | 2017-04-04 02:11:06 +0300 |
commit | 69d1d678e5eb1e47ad71cf13bfa5e81069e22019 (patch) | |
tree | a63164470d6c700ee8dfc5477b9e8f31b48b6046 | |
parent | 247371c321e770a9789e5698b3ef1e5cf628ba34 (diff) |
Fix handling of null constants in portable pdbs
-rw-r--r-- | Mono.Cecil/AssemblyReader.cs | 4 | ||||
-rw-r--r-- | Mono.Cecil/AssemblyWriter.cs | 1 | ||||
-rw-r--r-- | Test/Mono.Cecil.Tests/PortablePdbTests.cs | 16 |
3 files changed, 19 insertions, 2 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 43926c0..654bf48 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -2986,13 +2986,13 @@ namespace Mono.Cecil { value = Encoding.Unicode.GetString (bytes, 0, bytes.Length); } else value = null; - } else if (type.etype == ElementType.Object) { - value = null; } else if (type.IsTypeOf ("System", "Decimal")) { var b = signature.ReadByte (); value = new decimal (signature.ReadInt32 (), signature.ReadInt32 (), signature.ReadInt32 (), (b & 0x80) != 0, (byte) (b & 0x7f)); } else if (type.IsTypeOf ("System", "DateTime")) { value = new DateTime (signature.ReadInt64()); + } else if (type.etype == ElementType.Object || type.etype == ElementType.None || type.etype == ElementType.Class) { + value = null; } else value = signature.ReadConstantSignature (type.etype); diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs index 4cd79a3..cf08434 100644 --- a/Mono.Cecil/AssemblyWriter.cs +++ b/Mono.Cecil/AssemblyWriter.cs @@ -2146,6 +2146,7 @@ namespace Mono.Cecil { case ElementType.SzArray: case ElementType.Class: case ElementType.Object: + case ElementType.None: case ElementType.Var: case ElementType.MVar: signature.WriteInt32 (0); diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs index 107b537..1b4c5ec 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -388,6 +388,22 @@ namespace Mono.Cecil.Tests { } [Test] + public void NullClassConstant () + { + TestModule ("xattr.dll", module => { + var type = module.GetType ("Library"); + var method = type.GetMethod ("NullXAttributeConstant"); + var symbol = method.DebugInformation; + + Assert.IsNotNull (symbol); + Assert.AreEqual(1, symbol.Scope.Constants.Count); + + var a = symbol.Scope.Constants [0]; + Assert.AreEqual ("a", a.Name); + }, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider)); + } + + [Test] public void PortablePdbLineInfo () { TestModule ("line.exe", module => { |