Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created August 20, 2014 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/e8daeb96abca368a7acf to your computer and use it in GitHub Desktop.
Save guitarrapc/e8daeb96abca368a7acf to your computer and use it in GitHub Desktop.
LINQ Enumerable.Empty in PowerShell
function New-Empty ([string]$type)
{
$def = @"
public static System.Collections.Generic.IEnumerable<$type> Empty()
{
System.Collections.Generic.IEnumerable<$type> empty = System.Linq.Enumerable.Empty<$type>();
return empty;
}
"@
try
{
$name = [guid]::NewGuid().Guid -replace '-',''
$empty = Add-Type -MemberDefinition $def -name $name -passThru
return @($empty::Empty())
}
catch
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment