Created
December 12, 2019 02:00
-
-
Save lzybkr/c4b4f46f2f96f8b2dafb58ca502f1a9d to your computer and use it in GitHub Desktop.
Create a proxy object for static members of a .Net type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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