From 358d12ea9300c3225a1e2214a93c04d9c7a8dd58 Mon Sep 17 00:00:00 2001 From: nbkalex Date: Thu, 20 Jun 2019 23:22:30 +0300 Subject: [PATCH] Display com method signature with argument names (#9858) --- src/System.Management.Automation/engine/COM/ComUtil.cs | 9 +++++++-- test/powershell/engine/COM/COM.Basic.Tests.ps1 | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/COM/ComUtil.cs b/src/System.Management.Automation/engine/COM/ComUtil.cs index 9ec96bc9f..44e307a69 100644 --- a/src/System.Management.Automation/engine/COM/ComUtil.cs +++ b/src/System.Management.Automation/engine/COM/ComUtil.cs @@ -36,7 +36,11 @@ namespace System.Management.Automation 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 @@ namespace System.Management.Automation } // Append the function name - builder.Append(name); + builder.Append(names[0]); builder.Append(" ("); IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam; @@ -85,6 +89,7 @@ namespace System.Management.Automation else { builder.Append(paramstring); + builder.Append(" " + names[i + 1]); if (i < funcdesc.cParams - 1) { diff --git a/test/powershell/engine/COM/COM.Basic.Tests.ps1 b/test/powershell/engine/COM/COM.Basic.Tests.ps1 index 83dab2256..832b95c53 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" {