Last active
March 11, 2017 01:26
-
-
Save stknohg/5fc3ea1962e5ee5ccf5bc29e52d5bb21 to your computer and use it in GitHub Desktop.
PowerShellのClassのFieldとPropertyの扱いに関するメモ
This file contains 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
# | |
# PowerShell Class "Field" is converted to Property. | |
# | |
class PSClass | |
{ | |
[string]$Field1 = "F1" | |
} | |
Write-Output "Get Field information from [PSClass].GetMembers() -> returns Property" | |
[PSClass].GetMembers() | ? { $_.Name -eq "Field1" } | select Membertype | Out-String | |
Write-Output "Get Field information from [PSClass] | Get-Members -> returns Property" | |
$y = [PSClass]::new() | |
$y | Get-Member | ? { $_.Name -eq "Field1" } | select Membertype | Out-String | |
# | |
# Added C# Class Field is not converted to Property, but Get-Members returns "Property". | |
# | |
$code = @" | |
public sealed class CSClass | |
{ | |
public string Field1 = "F1"; | |
} | |
"@ | |
Add-Type -TypeDefinition $code | |
Write-Output "Get Field information from [CSClass].GetMembers() -> returns Field" | |
[CSClass].GetMembers() | ? { $_.Name -eq "Field1" } | select Membertype | Out-String | |
Write-Output "Get Field information from [CSClass] | Get-Members -> returns Property" | |
$t = [CSClass]::new() | |
$t | Get-Member | ? { $_.Name -eq "Field1" } | select Membertype | Out-String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PowerShell 5.1な環境での結果。