Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Remove [Out] by-value string parameter usage from System.Management. #34091

Merged
merged 7 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Security.Permissions;
using System.Runtime.Versioning;
using System.Text;

namespace WbemClient_v1 {}
namespace WbemUtilities_v1 {}
Expand Down Expand Up @@ -948,13 +949,13 @@ interface IWbemPathKeyList
[PreserveSig] int GetCount_([Out] out uint puKeyCount);
[PreserveSig] int SetKey_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags, [In] uint uCimType, [In] IntPtr pKeyVal);
[PreserveSig] int SetKey2_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags, [In] uint uCimType, [In] ref object pKeyVal);
[PreserveSig] int GetKey_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszKeyName, [In][Out] ref uint puKeyValBufSize, [In][Out] IntPtr pKeyVal, [Out] out uint puApparentCimType);
[PreserveSig] int GetKey2_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszKeyName, [In][Out] ref object pKeyValue, [Out] out uint puApparentCimType);
[PreserveSig] int GetKey_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszKeyName, [In][Out] ref uint puKeyValBufSize, [In][Out] IntPtr pKeyVal, [Out] out uint puApparentCimType);
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
[PreserveSig] int GetKey2_([In] uint uKeyIx, [In] uint uFlags, [In][Out] ref uint puNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszKeyName, [In][Out] ref object pKeyValue, [Out] out uint puApparentCimType);
[PreserveSig] int RemoveKey_([In][MarshalAs(UnmanagedType.LPWStr)] string wszName, [In] uint uFlags);
[PreserveSig] int RemoveAllKeys_([In] uint uFlags);
[PreserveSig] int MakeSingleton_([In] sbyte bSet);
[PreserveSig] int GetInfo_([In] uint uRequestedInfo, [Out] out ulong puResponse);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszText);
}

[GuidAttribute("3BC15AF2-736C-477E-9E51-238AF8667DCC")]
Expand All @@ -963,24 +964,24 @@ interface IWbemPathKeyList
interface IWbemPath
{
[PreserveSig] int SetText_([In] uint uMode, [In][MarshalAs(UnmanagedType.LPWStr)] string pszPath);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetText_([In] int lFlags, [In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszText);
[PreserveSig] int GetInfo_([In] uint uRequestedInfo, [Out] out ulong puResponse);
[PreserveSig] int SetServer_([In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int GetServer_([In][Out] ref uint puNameBufLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pName);
[PreserveSig] int GetServer_([In][Out] ref uint puNameBufLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pName);
[PreserveSig] int GetNamespaceCount_([Out] out uint puCount);
[PreserveSig] int SetNamespaceAt_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig] int GetNamespaceAt_([In] uint uIndex, [In][Out] ref uint puNameBufLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pName);
[PreserveSig] int SetNamespaceAt_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszName);
[PreserveSig] int GetNamespaceAt_([In] uint uIndex, [In][Out] ref uint puNameBufLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pName);
[PreserveSig] int RemoveNamespaceAt_([In] uint uIndex);
[PreserveSig] int RemoveAllNamespaces_();
[PreserveSig] int GetScopeCount_([Out] out uint puCount);
[PreserveSig] int SetScope_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszClass);
[PreserveSig] int SetScopeFromText_([In] uint uIndex, [In][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetScope_([In] uint uIndex, [In][Out] ref uint puClassNameBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszClass, [Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pKeyList);
[PreserveSig] int GetScopeAsText_([In] uint uIndex, [In][Out] ref uint puTextBufSize, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszText);
[PreserveSig] int GetScope_([In] uint uIndex, [In][Out] ref uint puClassNameBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszClass, [Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pKeyList);
[PreserveSig] int GetScopeAsText_([In] uint uIndex, [In][Out] ref uint puTextBufSize, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszText);
[PreserveSig] int RemoveScope_([In] uint uIndex);
[PreserveSig] int RemoveAllScopes_();
[PreserveSig] int SetClassName_([In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int GetClassName_([In][Out] ref uint puBuffLength, [In][Out][MarshalAs(UnmanagedType.LPWStr)] string pszName);
[PreserveSig] int GetClassName_([In][Out] ref uint puBuffLength, [Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2)] char[] pszName);
[PreserveSig] int GetKeyList_([Out][MarshalAs(UnmanagedType.Interface)] out IWbemPathKeyList pOut);
[PreserveSig] int CreateClassPart_([In] int lFlags, [In][MarshalAs(UnmanagedType.LPWStr)] string Name);
[PreserveSig] int DeleteClassPart_([In] int lFlags);
Expand Down
42 changes: 25 additions & 17 deletions src/System.Management/src/System/Management/ManagementPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Reflection;
using System.ComponentModel.Design.Serialization;
using System.Text;

namespace System.Management
{
Expand Down Expand Up @@ -321,8 +322,9 @@ private static string GetWbemPath(IWbemPath wbemPath)

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
status = wbemPath.GetText_(flags, ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen - 1];
status = wbemPath.GetText_(flags, ref bufLen, pathChars);
pathStr = new string(pathChars);
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -508,11 +510,12 @@ public string RelativePath

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
char[] pathChars = new char[(int)bufLen - 1];
status = wmiPath.GetText_(
(int) tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY,
ref bufLen,
pathStr);
pathChars);
pathStr = new string(pathChars);
}

if (status < 0)
Expand Down Expand Up @@ -607,8 +610,9 @@ public string Server

if (status >= 0 && 0 < uLen)
{
pathStr = new string ('0', (int) uLen-1);
status = wmiPath.GetServer_(ref uLen, pathStr);
char[] pathChars = new char[(int)uLen - 1];
status = wmiPath.GetServer_(ref uLen, pathChars);
pathStr = new string(pathChars);
}

if (status < 0)
Expand Down Expand Up @@ -706,11 +710,11 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0)
{
string nSpace = new string('0', (int) uLen-1);
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, nSpace);
char[] space = new char[(int)uLen - 1];
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, space);
if (status >= 0)
{
status = wmiPath.SetNamespaceAt_(i, nSpace);
status = wmiPath.SetNamespaceAt_(i, space);

if (status < 0)
break;
Expand Down Expand Up @@ -738,8 +742,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0 && uLen > 0)
{
string serverNew = new string ('0', (int) uLen-1);
status = wmiPathTmp.GetServer_(ref uLen, serverNew);
char[] newServerChars = new char[(int)uLen - 1];
status = wmiPathTmp.GetServer_(ref uLen, newServerChars);
string serverNew = new string(newServerChars);

if (status >= 0)
{
Expand All @@ -750,8 +755,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange)

if (status >= 0)
{
string serverOrg = new string('0', (int)uLen-1);
status = wmiPath.GetServer_(ref uLen, serverOrg);
char[] orgServerChars = new char[(int)uLen - 1];
status = wmiPath.GetServer_(ref uLen, orgServerChars);
string serverOrg = new string(orgServerChars);

if (status >= 0 && !string.Equals(serverOrg, serverNew, StringComparison.OrdinalIgnoreCase))
status = wmiPath.SetServer_(serverNew);
Expand Down Expand Up @@ -808,8 +814,9 @@ internal static string GetNamespacePath(IWbemPath wbemPath, int flags)

if (status >= 0 && bufLen > 0)
{
pathStr = new string ('0', (int) bufLen-1);
status = wbemPath.GetText_(flags, ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen - 1];
status = wbemPath.GetText_(flags, ref bufLen, pathChars);
pathStr = new string(pathChars);
}
}

Expand Down Expand Up @@ -905,8 +912,9 @@ internal string internalClassName

if (status >= 0 && 0 < bufLen)
{
pathStr = new string ('0', (int) bufLen-1);
status = wmiPath.GetClassName_(ref bufLen, pathStr);
char[] pathChars = new char[(int)bufLen - 1];
status = wmiPath.GetClassName_(ref bufLen, pathChars);
pathStr = new string(pathChars);

if (status < 0)
pathStr = string.Empty;
Expand Down