From c150558672c49a38a8e71a9f941fae3f6db91292 Mon Sep 17 00:00:00 2001 From: nbkalex Date: Sat, 8 Jun 2019 17:13:18 +0300 Subject: [PATCH 1/2] Display com method signature with argument names --- src/System.Management.Automation/engine/COM/ComUtil.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/COM/ComUtil.cs b/src/System.Management.Automation/engine/COM/ComUtil.cs index 9ec96bc9f44..44e307a69b5 100644 --- a/src/System.Management.Automation/engine/COM/ComUtil.cs +++ b/src/System.Management.Automation/engine/COM/ComUtil.cs @@ -36,7 +36,11 @@ internal class ComUtil internal static string GetMethodSignatureFromFuncDesc(COM.ITypeInfo typeinfo, COM.FUNCDESC funcdesc, bool isPropertyPut) { StringBuilder builder = new StringBuilder(); - string name = GetNameFromFuncDesc(typeinfo, funcdesc); + + // First value is function name + int namesCount = funcdesc.cParams + 1; + string[] names = new string[funcdesc.cParams + 1]; + typeinfo.GetNames(funcdesc.memid, names, namesCount, out namesCount); if (!isPropertyPut) { @@ -46,7 +50,7 @@ internal static string GetMethodSignatureFromFuncDesc(COM.ITypeInfo typeinfo, CO } // Append the function name - builder.Append(name); + builder.Append(names[0]); builder.Append(" ("); IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam; @@ -85,6 +89,7 @@ internal static string GetMethodSignatureFromFuncDesc(COM.ITypeInfo typeinfo, CO else { builder.Append(paramstring); + builder.Append(" " + names[i + 1]); if (i < funcdesc.cParams - 1) { From 776c661e5a2b225dd3d1ebd49486add457256e28 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Fri, 14 Jun 2019 13:57:07 +0500 Subject: [PATCH 2/2] Add test --- test/powershell/engine/COM/COM.Basic.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/powershell/engine/COM/COM.Basic.Tests.ps1 b/test/powershell/engine/COM/COM.Basic.Tests.ps1 index 83dab225651..832b95c53ea 100644 --- a/test/powershell/engine/COM/COM.Basic.Tests.ps1 +++ b/test/powershell/engine/COM/COM.Basic.Tests.ps1 @@ -48,6 +48,14 @@ try { [System.Object]::ReferenceEquals($element, $drives) | Should -BeFalse $element | Should -Be $drives.Item($element.DriveLetter) } + + It "ToString() should return method paramter names" { + $shell = New-Object -ComObject "Shell.Application" + $fullSignature = $shell.AddToRecent.ToString() + + $fullSignature | Should -BeExactly "void AddToRecent (Variant varFile, string bstrCategory)" + } + } Describe 'GetMember/SetMember/InvokeMember binders should have more restricted rule for COM object' -Tags "CI" {