Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3327,7 +3327,7 @@ private static HostException CreateHostException(
internal static void MimicKeyPress(INPUT[] inputs)
{
Dbg.Assert(inputs != null && inputs.Length > 0, "inputs should not be null or empty");
var numberOfSuccessfulEvents = NativeMethods.SendInput((uint)inputs.Length, inputs, ClrFacade.SizeOf<INPUT>());
var numberOfSuccessfulEvents = NativeMethods.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf<INPUT>());

if (numberOfSuccessfulEvents == 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.PowerShell.LocalAccounts/LocalAccounts/Sam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ private void OpenHandles()
// Open the "BuiltIn" domain
SecurityIdentifier sid = new SecurityIdentifier("S-1-5-32");
byte[] bSid = new byte[sid.BinaryLength];
int size = ClrFacade.SizeOf<byte>() * bSid.Length;
int size = Marshal.SizeOf<byte>() * bSid.Length;

pSid = Marshal.AllocHGlobal(size);

Expand Down Expand Up @@ -2247,7 +2247,7 @@ private void SetUserData(IntPtr userHandle,
if ((which & SamApi.USER_ALL_USERACCOUNTCONTROL) != 0)
info.UserAccountControl = uac;

buffer = Marshal.AllocHGlobal(ClrFacade.SizeOf<USER_ALL_INFORMATION>());
buffer = Marshal.AllocHGlobal(Marshal.SizeOf<USER_ALL_INFORMATION>());
Marshal.StructureToPtr<USER_ALL_INFORMATION>(info, buffer, false);

status = SamApi.SamSetInformationUser(userHandle,
Expand Down Expand Up @@ -2389,7 +2389,7 @@ private void SetSamDacl(IntPtr objectHandle, RawAcl rawAcl)

// create a new security descriptor
var sd = new SECURITY_DESCRIPTOR() { Revision = 1 };
ipsd = Marshal.AllocHGlobal(ClrFacade.SizeOf<SECURITY_DESCRIPTOR>());
ipsd = Marshal.AllocHGlobal(Marshal.SizeOf<SECURITY_DESCRIPTOR>());

if (rawAcl != null && rawAcl.BinaryLength > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class ComInvoker
// Alias of GUID_NULL. It's a GUID set to all zero
private static readonly Guid s_IID_NULL = new Guid();
// Size of the Variant struct
private static readonly int s_variantSize = ClrFacade.SizeOf<Variant>();
private static readonly int s_variantSize = Marshal.SizeOf<Variant>();

/// <summary>
/// Make a by-Ref VARIANT value based on the passed-in VARIANT argument
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/COM/ComUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal static string GetMethodSignatureFromFuncDesc(COM.ITypeInfo typeinfo, CO
builder.Append(" (");

IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam;
int ElementDescriptionSize = ClrFacade.SizeOf<COM.ELEMDESC>();
int ElementDescriptionSize = Marshal.SizeOf<COM.ELEMDESC>();

for (int i = 0; i < funcdesc.cParams; i++)
{
Expand Down Expand Up @@ -288,7 +288,7 @@ internal static ParameterInformation[] GetParameterInformation(COM.FUNCDESC func
ParameterInformation[] parameters = new ParameterInformation[cParams];

IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam;
int ElementDescriptionSize = ClrFacade.SizeOf<COM.ELEMDESC>();
int ElementDescriptionSize = Marshal.SizeOf<COM.ELEMDESC>();

for (int i = 0; i < cParams; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4468,7 +4468,7 @@ internal static List<string> GetFileShares(string machine, bool ignoreHidden)
{
for (int i = 0; i < numEntries; ++i)
{
IntPtr curInfoPtr = (IntPtr)((long)shBuf + (ClrFacade.SizeOf<SHARE_INFO_1>() * i));
IntPtr curInfoPtr = (IntPtr)((long)shBuf + (Marshal.SizeOf<SHARE_INFO_1>() * i));
SHARE_INFO_1 shareInfo = ClrFacade.PtrToStructure<SHARE_INFO_1>(curInfoPtr);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal MarshalledObject(IntPtr dataPtr)
/// <returns>MarshalledObject</returns>
internal static MarshalledObject Create<T>(T obj)
{
IntPtr ptr = Marshal.AllocHGlobal(ClrFacade.SizeOf<T>());
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<T>());
Marshal.StructureToPtr(obj, ptr, false);

// Now create the MarshalledObject and return.
Expand Down Expand Up @@ -665,7 +665,7 @@ internal WSManData_ManToUn(byte[] data)
_marshalledBuffer = dataToSendPtr; // Stored directly to enable graceful clean up during finalizer scenarios

Marshal.Copy(data, 0, _internalData.binaryOrTextData.data, _internalData.binaryOrTextData.bufferLength);
_marshalledObject = Marshal.AllocHGlobal(ClrFacade.SizeOf<WSManDataStruct>());
_marshalledObject = Marshal.AllocHGlobal(Marshal.SizeOf<WSManDataStruct>());
Marshal.StructureToPtr(_internalData, _marshalledObject, false);
}

Expand All @@ -686,7 +686,7 @@ internal WSManData_ManToUn(string data)
// marshal text data
_internalData.binaryOrTextData.data = Marshal.StringToHGlobalUni(data);
_marshalledBuffer = _internalData.binaryOrTextData.data; // Stored directly to enable graceful clean up during finalizer scenarios
_marshalledObject = Marshal.AllocHGlobal(ClrFacade.SizeOf<WSManDataStruct>());
_marshalledObject = Marshal.AllocHGlobal(Marshal.SizeOf<WSManDataStruct>());
Marshal.StructureToPtr(_internalData, _marshalledObject, false);
}

Expand Down Expand Up @@ -945,7 +945,7 @@ internal WSManStreamIDSet_ManToUn(string[] streamIds)
{
Dbg.Assert(streamIds != null, "stream ids cannot be null or empty");

int sizeOfIntPtr = ClrFacade.SizeOf<IntPtr>();
int sizeOfIntPtr = Marshal.SizeOf<IntPtr>();
_streamSetInfo = new WSManStreamIDSetStruct();
_streamSetInfo.streamIDsCount = streamIds.Length;
_streamSetInfo.streamIDs = Marshal.AllocHGlobal(sizeOfIntPtr * streamIds.Length);
Expand All @@ -965,7 +965,7 @@ internal void Dispose()
{
if (IntPtr.Zero != _streamSetInfo.streamIDs)
{
int sizeOfIntPtr = ClrFacade.SizeOf<IntPtr>();
int sizeOfIntPtr = Marshal.SizeOf<IntPtr>();
for (int index = 0; index < _streamSetInfo.streamIDsCount; index++)
{
IntPtr streamAddress = IntPtr.Zero;
Expand Down Expand Up @@ -1028,7 +1028,7 @@ internal static WSManStreamIDSet_UnToMan UnMarshal(IntPtr unmanagedData)
/*
* // TODO: Why didn't this work? It looks more efficient
idsArray = new string[resultInternal.streamIDsCount];
int sizeInBytes = ClrFacade.SizeOf<IntPtr>();
int sizeInBytes = Marshal.SizeOf<IntPtr>();
IntPtr perElementPtr = resultInternal.streamIDs;

for (int i = 0; i < resultInternal.streamIDsCount; i++)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ internal WSManOptionSet(WSManOption[] options)
{
Dbg.Assert(null != options, "options cannot be null");

int sizeOfOption = ClrFacade.SizeOf<WSManOption>();
int sizeOfOption = Marshal.SizeOf<WSManOption>();
_optionSet = new WSManOptionSetStruct();
_optionSet.optionsCount = options.Length;
_optionSet.optionsMustUnderstand = true;
Expand Down Expand Up @@ -1187,7 +1187,7 @@ internal static WSManOptionSet UnMarshal(WSManOptionSetStruct resultInternal)
{
tempOptions = new WSManOption[resultInternal.optionsCount];

int sizeInBytes = ClrFacade.SizeOf<WSManOption>();
int sizeInBytes = Marshal.SizeOf<WSManOption>();
IntPtr perElementPtr = resultInternal.options;

for (int i = 0; i < resultInternal.optionsCount; i++)
Expand Down Expand Up @@ -1230,7 +1230,7 @@ internal WSManCommandArgSet(byte[] firstArgument)
{
_internalData = new WSManCommandArgSetInternal();
_internalData.argsCount = 1;
_internalData.args = Marshal.AllocHGlobal(ClrFacade.SizeOf<IntPtr>());
_internalData.args = Marshal.AllocHGlobal(Marshal.SizeOf<IntPtr>());

// argument set takes only strings..but powershell's serialized pipeline might contain
// \0 (null characters) which are unacceptable in WSMan. So we are converting to Base64
Expand Down Expand Up @@ -1518,7 +1518,7 @@ internal static WSManEnvironmentVariableSet UnMarshal(IntPtr unmanagedData)
if (resultInternal.varsCount > 0)
{
varsArray = new WSManEnvironmentVariableInternal[resultInternal.varsCount];
int sizeInBytes = ClrFacade.SizeOf<WSManEnvironmentVariableInternal>();
int sizeInBytes = Marshal.SizeOf<WSManEnvironmentVariableInternal>();
IntPtr perElementPtr = resultInternal.vars;

for (int i = 0; i < resultInternal.varsCount; i++)
Expand Down Expand Up @@ -2251,7 +2251,7 @@ internal static WSManSelectorSet UnMarshal(WSManSelectorSetStruct resultInternal
if (resultInternal.numberKeys > 0)
{
tempKeys = new WSManKeyStruct[resultInternal.numberKeys];
int sizeInBytes = ClrFacade.SizeOf<WSManKeyStruct>();
int sizeInBytes = Marshal.SizeOf<WSManKeyStruct>();
IntPtr perElementPtr = resultInternal.keys;

for (int i = 0; i < resultInternal.numberKeys; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8144,7 +8144,7 @@ private static string WinInternalGetLinkType(string filePath)

using (SafeFileHandle handle = OpenReparsePoint(filePath, FileDesiredAccess.GenericRead))
{
int outBufferSize = ClrFacade.SizeOf<REPARSE_DATA_BUFFER_SYMBOLICLINK>();
int outBufferSize = Marshal.SizeOf<REPARSE_DATA_BUFFER_SYMBOLICLINK>();

IntPtr outBuffer = Marshal.AllocHGlobal(outBufferSize);
bool success = false;
Expand Down Expand Up @@ -8378,7 +8378,7 @@ private static string InternalGetTarget(SafeFileHandle handle)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")]
private static string WinInternalGetTarget(SafeFileHandle handle)
{
int outBufferSize = ClrFacade.SizeOf<REPARSE_DATA_BUFFER_SYMBOLICLINK>();
int outBufferSize = Marshal.SizeOf<REPARSE_DATA_BUFFER_SYMBOLICLINK>();

IntPtr outBuffer = Marshal.AllocHGlobal(outBufferSize);
bool success = false;
Expand Down Expand Up @@ -8546,7 +8546,7 @@ internal static bool DeleteJunction(string junctionPath)
using (SafeHandle handle = OpenReparsePoint(junctionPath, FileDesiredAccess.GenericWrite))
{
bool success = false;
int inOutBufferSize = ClrFacade.SizeOf<REPARSE_GUID_DATA_BUFFER>();
int inOutBufferSize = Marshal.SizeOf<REPARSE_GUID_DATA_BUFFER>();
IntPtr outBuffer = Marshal.AllocHGlobal(inOutBufferSize);
IntPtr inBuffer = Marshal.AllocHGlobal(inOutBufferSize);

Expand Down
9 changes: 0 additions & 9 deletions src/System.Management.Automation/utils/ClrFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ internal static SafeHandle GetSafeProcessHandle(Process process)

#region Marshal

/// <summary>
/// Facade for Marshal.SizeOf
/// </summary>
internal static int SizeOf<T>()
{
// Marshal.SizeOf(Type) is obsolete in CoreCLR
return Marshal.SizeOf<T>();
}

/// <summary>
/// Facade for Marshal.PtrToStructure
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/utils/PlatformInvokes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ internal static bool EnableTokenPrivilege(string privilegeName, ref TOKEN_PRIVIL
// The specified privilege is not enabled yet. Enable it.
newPrivilegeState.PrivilegeCount = 1;
newPrivilegeState.Privilege.Attributes = SE_PRIVILEGE_ENABLED;
int bufferSize = ClrFacade.SizeOf<TOKEN_PRIVILEGE>();
int bufferSize = Marshal.SizeOf<TOKEN_PRIVILEGE>();
int returnSize = 0;

// enable the specified privilege
Expand Down Expand Up @@ -406,7 +406,7 @@ internal static bool RestoreTokenPrivilege(string privilegeName, ref TOKEN_PRIVI
IntPtr tokenHandler = IntPtr.Zero;
if (OpenProcessToken(processHandler, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, out tokenHandler))
{
int bufferSize = ClrFacade.SizeOf<TOKEN_PRIVILEGE>();
int bufferSize = Marshal.SizeOf<TOKEN_PRIVILEGE>();
int returnSize = 0;

// restore the privilege state back to the previous privilege state
Expand Down