From f39f7c3d63a7fc7cbc22fc028c4d457ab469b865 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Wed, 27 Jul 2011 18:59:29 +0200 Subject: [PATCH] Use 'ref', not 'out', for passing arguments to a method parameter declared as "[In, Out] ref". --- ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs | 3 ++- ICSharpCode.Decompiler/Tests/PInvoke.cs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs b/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs index 396e97e1a..48bb1598a 100644 --- a/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs @@ -1012,7 +1012,8 @@ namespace ICSharpCode.Decompiler.Ast // Convert 'ref' into 'out' where necessary for (int i = 0; i < methodArgs.Count && i < cecilMethod.Parameters.Count; i++) { DirectionExpression dir = methodArgs[i] as DirectionExpression; - if (dir != null && cecilMethod.Parameters[i].IsOut) + ParameterDefinition p = cecilMethod.Parameters[i]; + if (dir != null && p.IsOut && !p.IsIn) dir.FieldDirection = FieldDirection.Out; } } diff --git a/ICSharpCode.Decompiler/Tests/PInvoke.cs b/ICSharpCode.Decompiler/Tests/PInvoke.cs index fe9b9b5bc..0c828ac69 100644 --- a/ICSharpCode.Decompiler/Tests/PInvoke.cs +++ b/ICSharpCode.Decompiler/Tests/PInvoke.cs @@ -84,4 +84,13 @@ public class PInvoke public void CustomMarshal2([MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "MyCompany.MyMarshaler", MarshalCookie = "Cookie")] object o) { } + + [DllImport("ws2_32.dll", SetLastError = true)] + internal static extern IntPtr ioctlsocket([In] IntPtr socketHandle, [In] int cmd, [In] [Out] ref int argp); + + public void CallMethodWithInOutParameter() + { + int num = 0; + PInvoke.ioctlsocket(IntPtr.Zero, 0, ref num); + } }