Skip to content

Instantly share code, notes, and snippets.

@lzybkr
Created December 12, 2019 02:00
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 lzybkr/c4b4f46f2f96f8b2dafb58ca502f1a9d to your computer and use it in GitHub Desktop.
Save lzybkr/c4b4f46f2f96f8b2dafb58ca502f1a9d to your computer and use it in GitHub Desktop.
Create a proxy object for static members of a .Net type
param([type]$Type)
$result = [pscustomobject]@{}
foreach ($property in $type.GetProperties([System.Reflection.BindingFlags]::Public -bor [System.Reflection.BindingFlags]::Static)) {
$name = $property.Name
$params = @{
InputObject = $result
MemberType = 'ScriptProperty'
Name = $property.Name
}
if ($property.GetMethod) {
$params.Value = {
$Type::$Name
}.GetNewClosure()
}
if ($property.SetMethod) {
$params.SecondValue = {
param($value)
$Type::$Name = $value
}.GetNewClosure()
}
Add-Member @params
}
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment