Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs (C#)

Code before:
            // The comparisons below are ordered by the likelihood of arguments being of those types.
            if (baseObj is string str)
            {
                return str;
            }

            // Special case some types to call 'ToString' on the object. For the rest, we return its
            // full type name to avoid calling a potentially expensive 'ToString' implementation.
            Type baseType = baseObj.GetType();
            if (baseType.IsEnum || baseType.IsPrimitive
                || baseType == typeof(Guid)
                || baseType == typeof(Uri)
                || baseType == typeof(Version)
                || baseType == typeof(SemanticVersion)
                || baseType == typeof(BigInteger)
                || baseType == typeof(decimal))
            {
                return baseObj.ToString();
            }

            return baseType.FullName;
        }

        internal static void LogMemberInvocation(string targetName, string name, object[] args)
        {
#if UNIX && !DEBUG
            // For efficiency this is a no-op on non-Windows platforms in release builds.
            return;
#else
            try
            {
                var contentName = "PowerShellMemberInvocation";
                var argsBuilder = new Text.StringBuilder();

                for (int i = 0; i < args.Length; i++)
                {
                    string value = ArgumentToString(args[i]);

                    if (i > 0)
                    {
                        argsBuilder.Append(", ");
                    }

                    argsBuilder.Append($"<{value}>");
                }

                string content = $"<{targetName}>.{name}({argsBuilder})";

                if (DumpLogAMSIContent.Value)
                {
                    Console.WriteLine("\n=== Amsi notification report content ===");

Review comment (performance):
Thanks for tackling this, but, given that there seems to be only one call to this method (in `Binders.cs`), wouldn't it be better for performance reasons to conditionally exclude that call instead?

Code after:
            // The comparisons below are ordered by the likelihood of arguments being of those types.
            if (baseObj is string str)
            {
                return str;
            }

            // Special case some types to call 'ToString' on the object. For the rest, we return its
            // full type name to avoid calling a potentially expensive 'ToString' implementation.
            Type baseType = baseObj.GetType();
            if (baseType.IsEnum || baseType.IsPrimitive
                || baseType == typeof(Guid)
                || baseType == typeof(Uri)
                || baseType == typeof(Version)
                || baseType == typeof(SemanticVersion)
                || baseType == typeof(BigInteger)
                || baseType == typeof(decimal))
            {
                return baseObj.ToString();
            }

            return baseType.FullName;
        }

        internal static void LogMemberInvocation(string targetName, string name, object[] args)
        {
            try
            {
                var contentName = "PowerShellMemberInvocation";
                var argsBuilder = new Text.StringBuilder();

                for (int i = 0; i < args.Length; i++)
                {
                    string value = ArgumentToString(args[i]);

                    if (i > 0)
                    {
                        argsBuilder.Append(", ");
                    }

                    argsBuilder.Append($"<{value}>");
                }

                string content = $"<{targetName}>.{name}({argsBuilder})";

                if (DumpLogAMSIContent.Value)
                {
                    Console.WriteLine("\n=== Amsi notification report content ===");
                    Console.WriteLine(content);
                }

                var success = AmsiUtils.ReportContent(