13
13
using System . Management . Automation . Internal . Host ;
14
14
using System . Management . Automation . Language ;
15
15
using System . Management . Automation . Runspaces ;
16
+ using System . Numerics ;
16
17
using System . Reflection ;
17
18
using System . Runtime . CompilerServices ;
18
19
using System . Text . RegularExpressions ;
@@ -3545,6 +3546,38 @@ internal static class MemberInvocationLoggingOps
3545
3546
}
3546
3547
) ;
3547
3548
3549
+ private static string ArgumentToString ( object arg )
3550
+ {
3551
+ object baseObj = PSObject . Base ( arg ) ;
3552
+ if ( baseObj is null )
3553
+ {
3554
+ // The argument is null or AutomationNull.Value.
3555
+ return "null" ;
3556
+ }
3557
+
3558
+ // The comparisons below are ordered by the likelihood of arguments being of those types.
3559
+ if ( baseObj is string str )
3560
+ {
3561
+ return str ;
3562
+ }
3563
+
3564
+ // Special case some types to call 'ToString' on the object. For the rest, we return its
3565
+ // full type name to avoid calling a potentially expensive 'ToString' implementation.
3566
+ Type baseType = baseObj . GetType ( ) ;
3567
+ if ( baseType . IsEnum || baseType . IsPrimitive
3568
+ || baseType == typeof ( Guid )
3569
+ || baseType == typeof ( Uri )
3570
+ || baseType == typeof ( Version )
3571
+ || baseType == typeof ( SemanticVersion )
3572
+ || baseType == typeof ( BigInteger )
3573
+ || baseType == typeof ( decimal ) )
3574
+ {
3575
+ return baseObj . ToString ( ) ;
3576
+ }
3577
+
3578
+ return baseType . FullName ;
3579
+ }
3580
+
3548
3581
internal static void LogMemberInvocation ( string targetName , string name , object [ ] args )
3549
3582
{
3550
3583
try
@@ -3554,7 +3587,7 @@ internal static void LogMemberInvocation(string targetName, string name, object[
3554
3587
3555
3588
for ( int i = 0 ; i < args . Length ; i ++ )
3556
3589
{
3557
- string value = args [ i ] is null ? "null" : args [ i ] . ToString ( ) ;
3590
+ string value = ArgumentToString ( args [ i ] ) ;
3558
3591
3559
3592
if ( i > 0 )
3560
3593
{
0 commit comments