diff --git a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs index 9f26f41e7..f967cf060 100644 --- a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs +++ b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs @@ -22,12 +22,10 @@ using System.Collections.Immutable; using System.IO; using System.Linq; using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using ICSharpCode.Decompiler.Metadata; -using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; using NUnit.Framework; @@ -677,6 +675,26 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem Assert.AreEqual((int)CharSet.Unicode, dllImport.NamedArguments.Single().Value); } + [Test] + public void DllImportAttributeWithPreserveSigFalse() + { + IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "DoNotPreserveSig"); + IAttribute dllImport = method.GetAttributes().Single(); + Assert.AreEqual("System.Runtime.InteropServices.DllImportAttribute", dllImport.AttributeType.FullName); + Assert.AreEqual("unmanaged.dll", dllImport.FixedArguments[0].Value); + Assert.AreEqual(false, dllImport.NamedArguments.Single().Value); + } + + [Test] + public void PreserveSigAttribute() + { + IMethod method = GetTypeDefinition(typeof(NonCustomAttributes)).Methods.Single(m => m.Name == "PreserveSigAsAttribute"); + IAttribute preserveSig = method.GetAttributes().Single(); + Assert.AreEqual("System.Runtime.InteropServices.PreserveSigAttribute", preserveSig.AttributeType.FullName); + Assert.IsTrue(preserveSig.FixedArguments.Length == 0); + Assert.IsTrue(preserveSig.NamedArguments.Length == 0); + } + [Test] public void InOutParametersOnRefMethod() { diff --git a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs index e819918a8..399c684c8 100644 --- a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs +++ b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemTestCase.cs @@ -153,6 +153,14 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem [DllImport("unmanaged.dll", CharSet = CharSet.Unicode)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DllMethod([In, Out] ref int p); + + [DllImport("unmanaged.dll", PreserveSig = false)] + public static extern bool DoNotPreserveSig(); + + [PreserveSig] + public static void PreserveSigAsAttribute() + { + } } [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8)] diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs index 3b5571a10..2af5acbcb 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs @@ -332,7 +332,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if ((implAttributes & MethodImplAttributes.PreserveSig) == MethodImplAttributes.PreserveSig) { implAttributes &= ~MethodImplAttributes.PreserveSig; } else { - dllImport.AddNamedArg("PreserveSig", KnownTypeCode.Boolean, true); + dllImport.AddNamedArg("PreserveSig", KnownTypeCode.Boolean, false); } if ((info.Attributes & MethodImportAttributes.SetLastError) == MethodImportAttributes.SetLastError)