@@ -13,7 +13,7 @@ namespace System.Management.Automation
13
13
/// <summary>
14
14
/// These are platform abstractions and platform specific implementations.
15
15
/// </summary>
16
- public static class Platform
16
+ public static partial class Platform
17
17
{
18
18
/// <summary>
19
19
/// True if the current platform is Linux.
@@ -453,18 +453,18 @@ internal static int NonWindowsWaitPid(int pid, bool nohang)
453
453
return Unix . NativeMethods . WaitPid ( pid , nohang ) ;
454
454
}
455
455
456
- internal static class Windows
456
+ internal static partial class Windows
457
457
{
458
458
/// <summary>The native methods class.</summary>
459
- internal static class NativeMethods
459
+ internal static partial class NativeMethods
460
460
{
461
461
private const string ole32Lib = "api-ms-win-core-com-l1-1-0.dll" ;
462
462
463
- [ DllImport ( ole32Lib ) ]
464
- internal static extern int CoInitializeEx ( IntPtr reserve , int coinit ) ;
463
+ [ LibraryImport ( ole32Lib ) ]
464
+ internal static partial int CoInitializeEx ( IntPtr reserve , int coinit ) ;
465
465
466
- [ DllImport ( ole32Lib ) ]
467
- internal static extern void CoUninitialize ( ) ;
466
+ [ LibraryImport ( ole32Lib ) ]
467
+ internal static partial void CoUninitialize ( ) ;
468
468
}
469
469
}
470
470
@@ -475,7 +475,7 @@ internal static class NativeMethods
475
475
// to a PAL value and calls strerror_r underneath to generate the message.
476
476
477
477
/// <summary>Unix specific implementations of required functionality.</summary>
478
- internal static class Unix
478
+ internal static partial class Unix
479
479
{
480
480
private static readonly Dictionary < int , string > usernameCache = new ( ) ;
481
481
private static readonly Dictionary < int , string > groupnameCache = new ( ) ;
@@ -925,35 +925,35 @@ public static int GetProcFSParentPid(int pid)
925
925
}
926
926
927
927
/// <summary>The native methods class.</summary>
928
- internal static class NativeMethods
928
+ internal static partial class NativeMethods
929
929
{
930
930
private const string psLib = "libpsl-native" ;
931
931
932
932
// Ansi is a misnomer, it is hardcoded to UTF-8 on Linux and macOS
933
933
// C bools are 1 byte and so must be marshaled as I1
934
934
935
- [ DllImport ( psLib , CharSet = CharSet . Ansi ) ]
936
- internal static extern int GetErrorCategory ( int errno ) ;
935
+ [ LibraryImport ( psLib ) ]
936
+ internal static partial int GetErrorCategory ( int errno ) ;
937
937
938
- [ DllImport ( psLib ) ]
939
- internal static extern int GetPPid ( int pid ) ;
938
+ [ LibraryImport ( psLib ) ]
939
+ internal static partial int GetPPid ( int pid ) ;
940
940
941
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
942
- internal static extern int GetLinkCount ( [ MarshalAs ( UnmanagedType . LPStr ) ] string filePath , out int linkCount ) ;
941
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 , SetLastError = true ) ]
942
+ internal static partial int GetLinkCount ( string filePath , out int linkCount ) ;
943
943
944
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
944
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
945
945
[ return : MarshalAs ( UnmanagedType . I1 ) ]
946
- internal static extern bool IsExecutable ( [ MarshalAs ( UnmanagedType . LPStr ) ] string filePath ) ;
946
+ internal static partial bool IsExecutable ( string filePath ) ;
947
947
948
- [ DllImport ( psLib , CharSet = CharSet . Ansi ) ]
949
- internal static extern uint GetCurrentThreadId ( ) ;
948
+ [ LibraryImport ( psLib ) ]
949
+ internal static partial uint GetCurrentThreadId ( ) ;
950
950
951
- [ DllImport ( psLib ) ]
951
+ [ LibraryImport ( psLib ) ]
952
952
[ return : MarshalAs ( UnmanagedType . Bool ) ]
953
- internal static extern bool KillProcess ( int pid ) ;
953
+ internal static partial bool KillProcess ( int pid ) ;
954
954
955
- [ DllImport ( psLib ) ]
956
- internal static extern int WaitPid ( int pid , bool nohang ) ;
955
+ [ LibraryImport ( psLib ) ]
956
+ internal static partial int WaitPid ( int pid , [ MarshalAs ( UnmanagedType . Bool ) ] bool nohang ) ;
957
957
958
958
// This is a struct tm from <time.h>.
959
959
[ StructLayout ( LayoutKind . Sequential ) ]
@@ -1003,29 +1003,25 @@ internal static UnixTm DateTimeToUnixTm(DateTime date)
1003
1003
return tm ;
1004
1004
}
1005
1005
1006
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1007
- internal static extern unsafe int SetDate ( UnixTm * tm ) ;
1006
+ [ LibraryImport ( psLib ) ]
1007
+ internal static unsafe partial int SetDate ( UnixTm * tm ) ;
1008
1008
1009
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1010
- internal static extern int CreateSymLink ( [ MarshalAs ( UnmanagedType . LPStr ) ] string filePath ,
1011
- [ MarshalAs ( UnmanagedType . LPStr ) ] string target ) ;
1009
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1010
+ internal static partial int CreateSymLink ( string filePath , string target ) ;
1012
1011
1013
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1014
- internal static extern int CreateHardLink ( [ MarshalAs ( UnmanagedType . LPStr ) ] string filePath ,
1015
- [ MarshalAs ( UnmanagedType . LPStr ) ] string target ) ;
1012
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1013
+ internal static partial int CreateHardLink ( string filePath , string target ) ;
1016
1014
1017
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1015
+ [ LibraryImport ( psLib ) ]
1018
1016
[ return : MarshalAs ( UnmanagedType . LPStr ) ]
1019
- internal static extern string GetUserFromPid ( int pid ) ;
1017
+ internal static partial string GetUserFromPid ( int pid ) ;
1020
1018
1021
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1019
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1022
1020
[ return : MarshalAs ( UnmanagedType . I1 ) ]
1023
- internal static extern bool IsSameFileSystemItem ( [ MarshalAs ( UnmanagedType . LPStr ) ] string filePathOne ,
1024
- [ MarshalAs ( UnmanagedType . LPStr ) ] string filePathTwo ) ;
1021
+ internal static partial bool IsSameFileSystemItem ( string filePathOne , string filePathTwo ) ;
1025
1022
1026
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1027
- internal static extern int GetInodeData ( [ MarshalAs ( UnmanagedType . LPStr ) ] string path ,
1028
- out ulong device , out ulong inode ) ;
1023
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1024
+ internal static partial int GetInodeData ( string path , out ulong device , out ulong inode ) ;
1029
1025
1030
1026
/// <summary>
1031
1027
/// This is a struct from getcommonstat.h in the native library.
@@ -1103,17 +1099,17 @@ internal struct CommonStatStruct
1103
1099
internal int IsSticky ;
1104
1100
}
1105
1101
1106
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1107
- internal static extern unsafe int GetCommonLStat ( string filePath , [ Out ] out CommonStatStruct cs ) ;
1102
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 , SetLastError = true ) ]
1103
+ internal static unsafe partial int GetCommonLStat ( string filePath , out CommonStatStruct cs ) ;
1108
1104
1109
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1110
- internal static extern unsafe int GetCommonStat ( string filePath , [ Out ] out CommonStatStruct cs ) ;
1105
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 , SetLastError = true ) ]
1106
+ internal static unsafe partial int GetCommonStat ( string filePath , out CommonStatStruct cs ) ;
1111
1107
1112
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1113
- internal static extern string GetPwUid ( int id ) ;
1108
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1109
+ internal static partial string GetPwUid ( int id ) ;
1114
1110
1115
- [ DllImport ( psLib , CharSet = CharSet . Ansi , SetLastError = true ) ]
1116
- internal static extern string GetGrGid ( int id ) ;
1111
+ [ LibraryImport ( psLib , StringMarshalling = StringMarshalling . Utf8 ) ]
1112
+ internal static partial string GetGrGid ( int id ) ;
1117
1113
}
1118
1114
}
1119
1115
}
0 commit comments