mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Change call to optional add in the binder expression
This commit is contained in:
committed by
Patrick Meinecke
parent
89921dd500
commit
06e2093e8c
@@ -6947,15 +6947,7 @@ namespace System.Management.Automation.Language
|
||||
// - Log method invocation to AMSI Notifications (can throw PSSecurityException)
|
||||
// - Invoke method
|
||||
string targetName = methodInfo.ReflectedType?.FullName ?? string.Empty;
|
||||
expr = Expression.Block(
|
||||
Expression.Call(
|
||||
CachedReflectionInfo.MemberInvocationLoggingOps_LogMemberInvocation,
|
||||
Expression.Constant(targetName),
|
||||
Expression.Constant(name),
|
||||
Expression.NewArrayInit(
|
||||
typeof(object),
|
||||
args.Select(static e => e.Expression.Cast(typeof(object))))),
|
||||
expr);
|
||||
MaybeAddMemberInvocationLogging(expr, targetName, name, args);
|
||||
|
||||
// If we're calling SteppablePipeline.{Begin|Process|End}, we don't want
|
||||
// to wrap exceptions - this is very much a special case to help error
|
||||
@@ -7566,6 +7558,33 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
private static Expression MaybeAddMemberInvocationLogging(
|
||||
Expression expr,
|
||||
string targetName,
|
||||
string name,
|
||||
DynamicMetaObject[] args)
|
||||
{
|
||||
#if UNIX && !DEBUG
|
||||
// For efficiency this is a no-op on non-Windows platforms in release builds.
|
||||
return expr;
|
||||
#else
|
||||
Expression[] invocationArgs = new Expression[args.Length];
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
invocationArgs[i] = args[i].Expression.Cast(typeof(object));
|
||||
}
|
||||
return Expression.Block(
|
||||
Expression.Call(
|
||||
CachedReflectionInfo.MemberInvocationLoggingOps_LogMemberInvocation,
|
||||
Expression.Constant(targetName),
|
||||
Expression.Constant(name),
|
||||
Expression.NewArrayInit(typeof(object), invocationArgs)),
|
||||
expr);
|
||||
#endif
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -3694,10 +3694,6 @@ namespace System.Management.Automation
|
||||
|
||||
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";
|
||||
@@ -3745,7 +3741,6 @@ namespace System.Management.Automation
|
||||
Console.WriteLine($"!!! Amsi notification report exception: {ex} !!!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user