Clean up ClrFacade.cs - remove ClrFacade.SizeOf<T>() (#4377)

This commit is contained in:
Dongbo Wang
2017-07-29 17:40:19 -07:00
committed by GitHub
parent 4eeeb4552c
commit 2c43140276
9 changed files with 24 additions and 33 deletions
@@ -3327,7 +3327,7 @@ namespace Microsoft.PowerShell
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)
{
@@ -1065,7 +1065,7 @@ namespace System.Management.Automation.SecurityAccountsManager
// 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);
@@ -2247,7 +2247,7 @@ namespace System.Management.Automation.SecurityAccountsManager
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,
@@ -2389,7 +2389,7 @@ namespace System.Management.Automation.SecurityAccountsManager
// 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)
{
@@ -24,7 +24,7 @@ namespace System.Management.Automation
// 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
@@ -49,7 +49,7 @@ namespace System.Management.Automation
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++)
{
@@ -288,7 +288,7 @@ namespace System.Management.Automation
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++)
{
@@ -4468,7 +4468,7 @@ namespace System.Management.Automation
{
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);
@@ -176,7 +176,7 @@ namespace System.Management.Automation.Remoting.Client
/// <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.
@@ -665,7 +665,7 @@ namespace System.Management.Automation.Remoting.Client
_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);
}
@@ -686,7 +686,7 @@ namespace System.Management.Automation.Remoting.Client
// 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);
}
@@ -945,7 +945,7 @@ namespace System.Management.Automation.Remoting.Client
{
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);
@@ -965,7 +965,7 @@ namespace System.Management.Automation.Remoting.Client
{
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;
@@ -1028,7 +1028,7 @@ namespace System.Management.Automation.Remoting.Client
/*
* // 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++)
@@ -1103,7 +1103,7 @@ namespace System.Management.Automation.Remoting.Client
{
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;
@@ -1187,7 +1187,7 @@ namespace System.Management.Automation.Remoting.Client
{
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++)
@@ -1230,7 +1230,7 @@ namespace System.Management.Automation.Remoting.Client
{
_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
@@ -1518,7 +1518,7 @@ namespace System.Management.Automation.Remoting.Client
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++)
@@ -2251,7 +2251,7 @@ namespace System.Management.Automation.Remoting.Client
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++)
@@ -8144,7 +8144,7 @@ namespace Microsoft.PowerShell.Commands
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;
@@ -8378,7 +8378,7 @@ namespace Microsoft.PowerShell.Commands
[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;
@@ -8546,7 +8546,7 @@ namespace Microsoft.PowerShell.Commands
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);
@@ -63,15 +63,6 @@ namespace System.Management.Automation
#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>
@@ -337,7 +337,7 @@ namespace System.Management.Automation
// 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
@@ -406,7 +406,7 @@ namespace System.Management.Automation
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