Filter out compiler generated types for Add-Type -PassThru (#18095)

This commit is contained in:
Dongbo Wang authored and GitHub committed 2022-09-15 13:34:09 -07:00
1 parent d702b52168
commit d0a91470c9
1 file changed
+9 -1
@@ -13,6 +13,7 @@ using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Security;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Loader;
using System.Security;
using System.Text;
@@ -891,7 +892,14 @@ namespace Microsoft.PowerShell.Commands
private void WriteTypes(Assembly assembly)
{
WriteObject(assembly.GetTypes(), true);
foreach (Type type in assembly.GetTypes())
{
// We only write out types that are not auto-generated by compiler.
if (type.GetCustomAttribute<CompilerGeneratedAttribute>() is null)
{
WriteObject(type);
}
}
}
#endregion LoadAssembly