diff options
Diffstat (limited to 'src/mscorlib/src/System/StubHelpers.cs')
-rw-r--r-- | src/mscorlib/src/System/StubHelpers.cs | 289 |
1 files changed, 142 insertions, 147 deletions
diff --git a/src/mscorlib/src/System/StubHelpers.cs b/src/mscorlib/src/System/StubHelpers.cs index 2d5926b923..f584ece6fc 100644 --- a/src/mscorlib/src/System/StubHelpers.cs +++ b/src/mscorlib/src/System/StubHelpers.cs @@ -3,8 +3,8 @@ // See the LICENSE file in the project root for more information. -namespace System.StubHelpers { - +namespace System.StubHelpers +{ using System.Text; using Microsoft.Win32; using System.Security; @@ -27,7 +27,7 @@ namespace System.StubHelpers { { byte[] buffer = new byte[(str.Length + 1) * Marshal.SystemMaxDBCSCharSize]; BCLDebug.Assert(buffer.Length != 0); - fixed (byte *bufferPtr = &buffer[0]) + fixed (byte* bufferPtr = &buffer[0]) { cbLength = str.ConvertToAnsi(bufferPtr, buffer.Length, fBestFit, fThrowOnUnmappableChar); } @@ -65,7 +65,7 @@ namespace System.StubHelpers { StubHelpers.CheckStringLength(strManaged.Length); int nb; - byte *pbNativeBuffer = (byte *)pNativeBuffer; + byte* pbNativeBuffer = (byte*)pNativeBuffer; if (pbNativeBuffer != null || Marshal.SystemMaxDBCSCharSize == 1) { @@ -100,11 +100,11 @@ namespace System.StubHelpers { Buffer.Memcpy(pbNativeBuffer, 0, bytes, 0, nb); } - pbNativeBuffer[nb] = 0x00; + pbNativeBuffer[nb] = 0x00; pbNativeBuffer[nb + 1] = 0x00; return (IntPtr)pbNativeBuffer; - } + } static internal unsafe string ConvertToManaged(IntPtr cstr) { @@ -122,7 +122,7 @@ namespace System.StubHelpers { internal static class UTF8Marshaler { - const int MAX_UTF8_CHAR_SIZE = 3; + private const int MAX_UTF8_CHAR_SIZE = 3; static internal unsafe IntPtr ConvertToNative(int flags, string strManaged, IntPtr pNativeBuffer) { if (null == strManaged) @@ -249,29 +249,29 @@ namespace System.StubHelpers { lengthInBytes++; } - byte *ptrToFirstChar; + byte* ptrToFirstChar; if (pNativeBuffer != IntPtr.Zero) { // If caller provided a buffer, construct the BSTR manually. The size // of the buffer must be at least (lengthInBytes + 6) bytes. #if _DEBUG - uint length = *((uint *)pNativeBuffer.ToPointer()); + uint length = *((uint*)pNativeBuffer.ToPointer()); BCLDebug.Assert(length >= lengthInBytes + 6, "BSTR localloc'ed buffer is too small"); #endif // _DEBUG // set length - *((uint *)pNativeBuffer.ToPointer()) = lengthInBytes; + *((uint*)pNativeBuffer.ToPointer()) = lengthInBytes; - ptrToFirstChar = (byte *)pNativeBuffer.ToPointer() + 4; + ptrToFirstChar = (byte*)pNativeBuffer.ToPointer() + 4; } else { // If not provided, allocate the buffer using SysAllocStringByteLen so // that odd-sized strings will be handled as well. - ptrToFirstChar = (byte *)Win32Native.SysAllocStringByteLen(null, lengthInBytes).ToPointer(); + ptrToFirstChar = (byte*)Win32Native.SysAllocStringByteLen(null, lengthInBytes).ToPointer(); - if (ptrToFirstChar == null) + if (ptrToFirstChar == null) { throw new OutOfMemoryException(); } @@ -282,7 +282,7 @@ namespace System.StubHelpers { { Buffer.Memcpy( ptrToFirstChar, - (byte *)ch, + (byte*)ch, (strManaged.Length + 1) * 2); } @@ -334,7 +334,7 @@ namespace System.StubHelpers { if ((length & 1) == 1) { // odd-sized strings need to have the trailing byte saved in their sync block - ret.SetTrailByte(((byte *)bstr.ToPointer())[length - 1]); + ret.SetTrailByte(((byte*)bstr.ToPointer())[length - 1]); } return ret; @@ -363,7 +363,7 @@ namespace System.StubHelpers { } byte* pNative; - + cch = strManaged.Length; StubHelpers.CheckStringLength(cch); @@ -373,7 +373,7 @@ namespace System.StubHelpers { pNative = (byte*)Marshal.AllocCoTaskMem(nbytes); int* pLength = (int*)pNative; - + pNative = pNative + sizeof(uint); if (0 == cch) @@ -405,7 +405,7 @@ namespace System.StubHelpers { return new String((sbyte*)pNative, 0, cch); } - + static internal unsafe void ClearNative(IntPtr pNative) { if (IntPtr.Zero != pNative) @@ -431,8 +431,8 @@ namespace System.StubHelpers { StubHelpers.CheckStringLength(length); - byte[] bytes = null; - int nb = 0; + byte[] bytes = null; + int nb = 0; if (length > 0) { @@ -499,23 +499,23 @@ namespace System.StubHelpers { public Int64 UniversalTime; }; - internal static class DateTimeOffsetMarshaler { - + internal static class DateTimeOffsetMarshaler + { // Numer of ticks counted between 0001-01-01, 00:00:00 and 1601-01-01, 00:00:00. // You can get this through: (new DateTimeOffset(1601, 1, 1, 0, 0, 1, TimeSpan.Zero)).Ticks; private const Int64 ManagedUtcTicksAtNativeZero = 504911232000000000; - internal static void ConvertToNative(ref DateTimeOffset managedDTO, out DateTimeNative dateTime) { - + internal static void ConvertToNative(ref DateTimeOffset managedDTO, out DateTimeNative dateTime) + { Int64 managedUtcTicks = managedDTO.UtcTicks; dateTime.UniversalTime = managedUtcTicks - ManagedUtcTicksAtNativeZero; } - internal static void ConvertToManaged(out DateTimeOffset managedLocalDTO, ref DateTimeNative nativeTicks) { - + internal static void ConvertToManaged(out DateTimeOffset managedLocalDTO, ref DateTimeNative nativeTicks) + { Int64 managedUtcTicks = ManagedUtcTicksAtNativeZero + nativeTicks.UniversalTime; DateTimeOffset managedUtcDTO = new DateTimeOffset(managedUtcTicks, TimeSpan.Zero); - + // Some Utc times cannot be represented in local time in certain timezones. E.g. 0001-01-01 12:00:00 AM cannot // be represented in any timezones with a negative offset from Utc. We throw an ArgumentException in that case. managedLocalDTO = managedUtcDTO.ToLocalTime(true); @@ -532,7 +532,7 @@ namespace System.StubHelpers { internal static unsafe IntPtr ConvertToNative(string managed) { if (!Environment.IsWinRTSupported) - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); if (managed == null) throw new ArgumentNullException(); // We don't have enough information to get the argument name @@ -549,16 +549,16 @@ namespace System.StubHelpers { // the returned HSTRING object. If the string is not pinned, or becomes unpinned before the HSTRING's // lifetime ends, the HSTRING instance will be corrupted. internal static unsafe IntPtr ConvertToNativeReference(string managed, - [Out] HSTRING_HEADER *hstringHeader) + [Out] HSTRING_HEADER* hstringHeader) { if (!Environment.IsWinRTSupported) - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); if (managed == null) throw new ArgumentNullException(); // We don't have enough information to get the argument name // The string must also be pinned by the caller to ConvertToNativeReference, which also owns // the HSTRING_HEADER. - fixed (char *pManaged = managed) + fixed (char* pManaged = managed) { IntPtr hstring; int hrCreate = System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.WindowsCreateStringReference(pManaged, managed.Length, hstringHeader, &hstring); @@ -571,7 +571,7 @@ namespace System.StubHelpers { { if (!Environment.IsWinRTSupported) { - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); } return WindowsRuntimeMarshal.HStringToString(hstring); @@ -651,15 +651,14 @@ namespace System.StubHelpers { [MethodImplAttribute(MethodImplOptions.InternalCall)] static unsafe internal extern IntPtr CreateNativeUriInstanceHelper(char* rawUri, int strLen); - + static unsafe internal IntPtr CreateNativeUriInstance(string rawUri) { - fixed(char* pManaged = rawUri) + fixed (char* pManaged = rawUri) { return CreateNativeUriInstanceHelper(pManaged, rawUri.Length); } } - } // class InterfaceMarshaler [FriendAccessAllowed] @@ -703,7 +702,7 @@ namespace System.StubHelpers { { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void CreateMarshaler(IntPtr pMarshalState, IntPtr pMT, int dwFlags); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ConvertSpaceToNative(IntPtr pMarshalState, ref object pManagedHome, IntPtr pNativeHome); @@ -719,7 +718,7 @@ namespace System.StubHelpers { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ClearNative(IntPtr pMarshalState, IntPtr pNativeHome, int cElements); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ClearNativeContents(IntPtr pMarshalState, IntPtr pNativeHome, int cElements); } // class MngdNativeArrayMarshaler @@ -729,7 +728,7 @@ namespace System.StubHelpers { { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void CreateMarshaler(IntPtr pMarshalState, IntPtr pMT, int iRank, int dwFlags); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ConvertSpaceToNative(IntPtr pMarshalState, ref object pManagedHome, IntPtr pNativeHome); @@ -750,7 +749,7 @@ namespace System.StubHelpers { { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void CreateMarshaler(IntPtr pMarshalState, IntPtr pMT, IntPtr cbElementSize, ushort vt); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void ConvertSpaceToNative(IntPtr pMarshalState, ref object pManagedHome, IntPtr pNativeHome); @@ -761,7 +760,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - DateTimeNative *nativeBuffer = *(DateTimeNative **)pNativeHome; + DateTimeNative* nativeBuffer = *(DateTimeNative**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { DateTimeOffsetMarshaler.ConvertToNative(ref managedArray[i], out nativeBuffer[i]); @@ -773,7 +772,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - TypeNameNative *nativeBuffer = *(TypeNameNative **)pNativeHome; + TypeNameNative* nativeBuffer = *(TypeNameNative**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { SystemTypeMarshaler.ConvertToNative(managedArray[i], &nativeBuffer[i]); @@ -785,7 +784,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - Int32 *nativeBuffer = *(Int32 **)pNativeHome; + Int32* nativeBuffer = *(Int32**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { nativeBuffer[i] = HResultExceptionMarshaler.ConvertToNative(managedArray[i]); @@ -798,7 +797,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - IntPtr *nativeBuffer = *(IntPtr **)pNativeHome; + IntPtr* nativeBuffer = *(IntPtr**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { nativeBuffer[i] = NullableMarshaler.ConvertToNative<T>(ref managedArray[i]); @@ -810,7 +809,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - IntPtr *nativeBuffer = *(IntPtr **)pNativeHome; + IntPtr* nativeBuffer = *(IntPtr**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { nativeBuffer[i] = KeyValuePairMarshaler.ConvertToNative<K, V>(ref managedArray[i]); @@ -828,7 +827,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - DateTimeNative *nativeBuffer = *(DateTimeNative **)pNativeHome; + DateTimeNative* nativeBuffer = *(DateTimeNative**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { DateTimeOffsetMarshaler.ConvertToManaged(out managedArray[i], ref nativeBuffer[i]); @@ -840,7 +839,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - TypeNameNative *nativeBuffer = *(TypeNameNative **)pNativeHome; + TypeNameNative* nativeBuffer = *(TypeNameNative**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { SystemTypeMarshaler.ConvertToManaged(&nativeBuffer[i], ref managedArray[i]); @@ -852,7 +851,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - Int32 *nativeBuffer = *(Int32 **)pNativeHome; + Int32* nativeBuffer = *(Int32**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { managedArray[i] = HResultExceptionMarshaler.ConvertToManaged(nativeBuffer[i]); @@ -865,7 +864,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - IntPtr *nativeBuffer = *(IntPtr **)pNativeHome; + IntPtr* nativeBuffer = *(IntPtr**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { managedArray[i] = NullableMarshaler.ConvertToManaged<T>(nativeBuffer[i]); @@ -877,7 +876,7 @@ namespace System.StubHelpers { { if (managedArray != null) { - IntPtr *nativeBuffer = *(IntPtr **)pNativeHome; + IntPtr* nativeBuffer = *(IntPtr**)pNativeHome; for (int i = 0; i < managedArray.Length; i++) { managedArray[i] = KeyValuePairMarshaler.ConvertToManaged<K, V>(nativeBuffer[i]); @@ -892,7 +891,7 @@ namespace System.StubHelpers { { Debug.Assert(Environment.IsWinRTSupported); - TypeNameNative *pNativeTypeArray = *(TypeNameNative **)pNativeHome; + TypeNameNative* pNativeTypeArray = *(TypeNameNative**)pNativeHome; if (pNativeTypeArray != null) { for (int i = 0; i < cElements; ++i) @@ -910,7 +909,7 @@ namespace System.StubHelpers { { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void CreateMarshaler(IntPtr pMarshalState, IntPtr pCMHelper); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ConvertContentsToNative(IntPtr pMarshalState, ref object pManagedHome, IntPtr pNativeHome); @@ -927,7 +926,7 @@ namespace System.StubHelpers { internal struct AsAnyMarshaler { private const ushort VTHACK_ANSICHAR = 253; - private const ushort VTHACK_WINBOOL = 254; + private const ushort VTHACK_WINBOOL = 254; private enum BackPropAction { @@ -950,9 +949,9 @@ namespace System.StubHelpers { // Cleanup list to be destroyed when clearing the native view (for layouts with SafeHandles). private CleanupWorkList cleanupWorkList; - private static bool IsIn(int dwFlags) { return ((dwFlags & 0x10000000) != 0); } - private static bool IsOut(int dwFlags) { return ((dwFlags & 0x20000000) != 0); } - private static bool IsAnsi(int dwFlags) { return ((dwFlags & 0x00FF0000) != 0); } + private static bool IsIn(int dwFlags) { return ((dwFlags & 0x10000000) != 0); } + private static bool IsOut(int dwFlags) { return ((dwFlags & 0x20000000) != 0); } + private static bool IsAnsi(int dwFlags) { return ((dwFlags & 0x00FF0000) != 0); } private static bool IsThrowOn(int dwFlags) { return ((dwFlags & 0x0000FF00) != 0); } private static bool IsBestFit(int dwFlags) { return ((dwFlags & 0x000000FF) != 0); } @@ -962,9 +961,9 @@ namespace System.StubHelpers { BCLDebug.Assert(pvArrayMarshaler != IntPtr.Zero, "pvArrayMarshaler must not be null"); this.pvArrayMarshaler = pvArrayMarshaler; - this.backPropAction = BackPropAction.None; - this.layoutType = null; - this.cleanupWorkList = null; + backPropAction = BackPropAction.None; + layoutType = null; + cleanupWorkList = null; } #region ConvertToNative helpers @@ -976,35 +975,35 @@ namespace System.StubHelpers { switch (Type.GetTypeCode(elementType)) { - case TypeCode.SByte: vt = VarEnum.VT_I1; break; - case TypeCode.Byte: vt = VarEnum.VT_UI1; break; - case TypeCode.Int16: vt = VarEnum.VT_I2; break; - case TypeCode.UInt16: vt = VarEnum.VT_UI2; break; - case TypeCode.Int32: vt = VarEnum.VT_I4; break; - case TypeCode.UInt32: vt = VarEnum.VT_UI4; break; - case TypeCode.Int64: vt = VarEnum.VT_I8; break; - case TypeCode.UInt64: vt = VarEnum.VT_UI8; break; - case TypeCode.Single: vt = VarEnum.VT_R4; break; - case TypeCode.Double: vt = VarEnum.VT_R8; break; - case TypeCode.Char: vt = (IsAnsi(dwFlags) ? (VarEnum)VTHACK_ANSICHAR : VarEnum.VT_UI2); break; + case TypeCode.SByte: vt = VarEnum.VT_I1; break; + case TypeCode.Byte: vt = VarEnum.VT_UI1; break; + case TypeCode.Int16: vt = VarEnum.VT_I2; break; + case TypeCode.UInt16: vt = VarEnum.VT_UI2; break; + case TypeCode.Int32: vt = VarEnum.VT_I4; break; + case TypeCode.UInt32: vt = VarEnum.VT_UI4; break; + case TypeCode.Int64: vt = VarEnum.VT_I8; break; + case TypeCode.UInt64: vt = VarEnum.VT_UI8; break; + case TypeCode.Single: vt = VarEnum.VT_R4; break; + case TypeCode.Double: vt = VarEnum.VT_R8; break; + case TypeCode.Char: vt = (IsAnsi(dwFlags) ? (VarEnum)VTHACK_ANSICHAR : VarEnum.VT_UI2); break; case TypeCode.Boolean: vt = (VarEnum)VTHACK_WINBOOL; break; case TypeCode.Object: - { - if (elementType == typeof(IntPtr)) - { - vt = (IntPtr.Size == 4 ? VarEnum.VT_I4 : VarEnum.VT_I8); - } - else if (elementType == typeof(UIntPtr)) { - vt = (IntPtr.Size == 4 ? VarEnum.VT_UI4 : VarEnum.VT_UI8); + if (elementType == typeof(IntPtr)) + { + vt = (IntPtr.Size == 4 ? VarEnum.VT_I4 : VarEnum.VT_I8); + } + else if (elementType == typeof(UIntPtr)) + { + vt = (IntPtr.Size == 4 ? VarEnum.VT_UI4 : VarEnum.VT_UI8); + } + else goto default; + break; } - else goto default; - break; - } default: - throw new ArgumentException(Environment.GetResourceString("Arg_NDirectBadObject")); + throw new ArgumentException(SR.Arg_NDirectBadObject); } // marshal the object as C-style array (UnmanagedType.LPArray) @@ -1152,7 +1151,7 @@ namespace System.StubHelpers { // marshal the object as class with layout (UnmanagedType.LPStruct) if (IsIn(dwFlags)) { - StubHelpers.FmtClassUpdateNativeInternal(pManagedHome, (byte *)pNativeHome.ToPointer(), ref cleanupWorkList); + StubHelpers.FmtClassUpdateNativeInternal(pManagedHome, (byte*)pNativeHome.ToPointer(), ref cleanupWorkList); } if (IsOut(dwFlags)) { @@ -1171,7 +1170,7 @@ namespace System.StubHelpers { return IntPtr.Zero; if (pManagedHome is ArrayWithOffset) - throw new ArgumentException(Environment.GetResourceString("Arg_MarshalAsAnyRestriction")); + throw new ArgumentException(SR.Arg_MarshalAsAnyRestriction); IntPtr pNativeHome; @@ -1203,7 +1202,7 @@ namespace System.StubHelpers { else { // this type is not supported for AsAny marshaling - throw new ArgumentException(Environment.GetResourceString("Arg_NDirectBadObject")); + throw new ArgumentException(SR.Arg_NDirectBadObject); } } @@ -1215,35 +1214,35 @@ namespace System.StubHelpers { switch (backPropAction) { case BackPropAction.Array: - { - MngdNativeArrayMarshaler.ConvertContentsToManaged( - pvArrayMarshaler, - ref pManagedHome, - new IntPtr(&pNativeHome)); - break; - } + { + MngdNativeArrayMarshaler.ConvertContentsToManaged( + pvArrayMarshaler, + ref pManagedHome, + new IntPtr(&pNativeHome)); + break; + } case BackPropAction.Layout: - { - StubHelpers.FmtClassUpdateCLRInternal(pManagedHome, (byte *)pNativeHome.ToPointer()); - break; - } + { + StubHelpers.FmtClassUpdateCLRInternal(pManagedHome, (byte*)pNativeHome.ToPointer()); + break; + } case BackPropAction.StringBuilderAnsi: - { - sbyte* ptr = (sbyte*)pNativeHome.ToPointer(); - ((StringBuilder)pManagedHome).ReplaceBufferAnsiInternal(ptr, Win32Native.lstrlenA(pNativeHome)); - break; - } + { + sbyte* ptr = (sbyte*)pNativeHome.ToPointer(); + ((StringBuilder)pManagedHome).ReplaceBufferAnsiInternal(ptr, Win32Native.lstrlenA(pNativeHome)); + break; + } case BackPropAction.StringBuilderUnicode: - { - char* ptr = (char*)pNativeHome.ToPointer(); - ((StringBuilder)pManagedHome).ReplaceBufferInternal(ptr, Win32Native.lstrlenW(pNativeHome)); - break; - } + { + char* ptr = (char*)pNativeHome.ToPointer(); + ((StringBuilder)pManagedHome).ReplaceBufferInternal(ptr, Win32Native.lstrlenW(pNativeHome)); + break; + } - // nothing to do for BackPropAction.None + // nothing to do for BackPropAction.None } } @@ -1264,7 +1263,7 @@ namespace System.StubHelpers { #if FEATURE_COMINTEROP internal static class NullableMarshaler - { + { static internal IntPtr ConvertToNative<T>(ref Nullable<T> pManaged) where T : struct { if (pManaged.HasValue) @@ -1277,7 +1276,7 @@ namespace System.StubHelpers { return IntPtr.Zero; } } - + static internal void ConvertToManagedRetVoid<T>(IntPtr pNative, ref Nullable<T> retObj) where T : struct { retObj = ConvertToManaged<T>(pNative); @@ -1302,9 +1301,8 @@ namespace System.StubHelpers { [StructLayout(LayoutKind.Sequential)] internal struct TypeNameNative { - - internal IntPtr typeName; // HSTRING - internal TypeKind typeKind; // TypeKind enum + internal IntPtr typeName; // HSTRING + internal TypeKind typeKind; // TypeKind enum } // Corresponds to Windows.UI.Xaml.TypeSource @@ -1319,26 +1317,26 @@ namespace System.StubHelpers { { [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern string ConvertToWinRTTypeName(System.Type managedType, out bool isPrimitive); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern System.Type GetTypeFromWinRTTypeName(string typeName, out bool isPrimitive); } - + internal static class SystemTypeMarshaler - { - internal static unsafe void ConvertToNative(System.Type managedType, TypeNameNative *pNativeType) + { + internal static unsafe void ConvertToNative(System.Type managedType, TypeNameNative* pNativeType) { if (!Environment.IsWinRTSupported) { - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); } - + string typeName; if (managedType != null) { if (managedType.GetType() != typeof(System.RuntimeType)) { // The type should be exactly System.RuntimeType (and not its child System.ReflectionOnlyType, or other System.Type children) - throw new ArgumentException(Environment.GetResourceString("Argument_WinRTSystemRuntimeType", managedType.GetType().ToString())); + throw new ArgumentException(SR.Format(SR.Argument_WinRTSystemRuntimeType, managedType.GetType().ToString())); } bool isPrimitive; @@ -1368,14 +1366,14 @@ namespace System.StubHelpers { int hrCreate = System.Runtime.InteropServices.WindowsRuntime.UnsafeNativeMethods.WindowsCreateString(typeName, typeName.Length, &pNativeType->typeName); Marshal.ThrowExceptionForHR(hrCreate, new IntPtr(-1)); } - - internal static unsafe void ConvertToManaged(TypeNameNative *pNativeType, ref System.Type managedType) + + internal static unsafe void ConvertToManaged(TypeNameNative* pNativeType, ref System.Type managedType) { if (!Environment.IsWinRTSupported) { - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); } - + string typeName = WindowsRuntimeMarshal.HStringToString(pNativeType->typeName); if (String.IsNullOrEmpty(typeName)) { @@ -1394,11 +1392,11 @@ namespace System.StubHelpers { // TypeSource must match if (isPrimitive != (pNativeType->typeKind == TypeKind.Primitive)) - throw new ArgumentException(Environment.GetResourceString("Argument_Unexpected_TypeSource")); + throw new ArgumentException(SR.Argument_Unexpected_TypeSource); } } - - internal static unsafe void ClearNative(TypeNameNative *pNativeType) + + internal static unsafe void ClearNative(TypeNameNative* pNativeType) { Debug.Assert(Environment.IsWinRTSupported); @@ -1416,7 +1414,7 @@ namespace System.StubHelpers { { if (!Environment.IsWinRTSupported) { - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); } if (ex == null) @@ -1431,7 +1429,7 @@ namespace System.StubHelpers { if (!Environment.IsWinRTSupported) { - throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); + throw new PlatformNotSupportedException(SR.PlatformNotSupported_WinRT); } Exception e = null; @@ -1448,13 +1446,13 @@ namespace System.StubHelpers { } // class HResultExceptionMarshaler internal static class KeyValuePairMarshaler - { + { internal static IntPtr ConvertToNative<K, V>([In] ref KeyValuePair<K, V> pair) { IKeyValuePair<K, V> impl = new CLRIKeyValuePairImpl<K, V>(ref pair); return Marshal.GetComInterfaceForObject(impl, typeof(IKeyValuePair<K, V>)); } - + internal static KeyValuePair<K, V> ConvertToManaged<K, V>(IntPtr pInsp) { object obj = InterfaceMarshaler.ConvertToManagedWithoutUnboxing(pInsp); @@ -1475,10 +1473,10 @@ namespace System.StubHelpers { [StructLayout(LayoutKind.Sequential)] internal struct NativeVariant { - ushort vt; - ushort wReserved1; - ushort wReserved2; - ushort wReserved3; + private ushort vt; + private ushort wReserved1; + private ushort wReserved2; + private ushort wReserved3; // The union portion of the structure contains at least one 64-bit type that on some 32-bit platforms // (notably ARM) requires 64-bit alignment. So on 32-bit platforms we'll actually size the variant @@ -1487,8 +1485,8 @@ namespace System.StubHelpers { // VARIANTs). Note that the field names here don't matter: none of the code refers to these fields, // the structure just exists to provide size information to the IL marshaler. #if BIT64 - IntPtr data1; - IntPtr data2; + private IntPtr data1; + private IntPtr data2; #else Int64 data1; #endif @@ -1514,7 +1512,7 @@ namespace System.StubHelpers { internal sealed class CleanupWorkList { private List<CleanupWorkListElement> m_list = new List<CleanupWorkListElement>(); - + public void Add(CleanupWorkListElement elem) { BCLDebug.Assert(elem.m_owned == false, "m_owned is supposed to be false and set later by DangerousAddRef"); @@ -1612,19 +1610,17 @@ namespace System.StubHelpers { //------------------------------------------------------- // SafeHandle Helpers //------------------------------------------------------- - + // AddRefs the SH and returns the underlying unmanaged handle. static internal IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success) { if (pHandle == null) { - throw new ArgumentNullException(nameof(pHandle), Environment.GetResourceString("ArgumentNull_SafeHandle")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle); } - Contract.EndContractBlock(); pHandle.DangerousAddRef(ref success); - - return (success ? pHandle.DangerousGetHandle() : IntPtr.Zero); + return pHandle.DangerousGetHandle(); } // Releases the SH (to be called from finally block). @@ -1632,9 +1628,8 @@ namespace System.StubHelpers { { if (pHandle == null) { - throw new ArgumentNullException(nameof(pHandle), Environment.GetResourceString("ArgumentNull_SafeHandle")); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle); } - Contract.EndContractBlock(); try { @@ -1673,7 +1668,7 @@ namespace System.StubHelpers { //------------------------------------------------------- // Helper for the MDA RaceOnRCWCleanup //------------------------------------------------------- - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void StubRegisterRCW(object pThis); @@ -1727,7 +1722,7 @@ namespace System.StubHelpers { { if (length > 0x7ffffff0) { - throw new MarshalDirectiveException(Environment.GetResourceString("Marshaler_StringTooLong")); + throw new MarshalDirectiveException(SR.Marshaler_StringTooLong); } } @@ -1736,7 +1731,7 @@ namespace System.StubHelpers { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void DecimalCanonicalizeInternal(ref Decimal dec); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal unsafe extern void FmtClassUpdateNativeInternal(object obj, byte* pNative, ref CleanupWorkList pCleanupWorkList); [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -1751,10 +1746,10 @@ namespace System.StubHelpers { [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void MarshalToManagedVaListInternal(IntPtr va_list, IntPtr pArgIterator); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern uint CalcVaListSize(IntPtr va_list); - + [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern void ValidateObject(object obj, IntPtr pMD, object pThis); |