-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
9 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Operators | ||
|
||
## Keyword Operator | ||
|
||
| Desc | Operator | Example | Reference | | ||
| --------------- | --------------- | --------------- |--------------- | | ||
| Split a string by separator into a `string[]`| `-split` | `'1,2,3' -split ','` | [about_Split](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-7.4) | | ||
| Item1.2 | Item2.2 | Item3.2 | | | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Variable | ||
|
||
## Declaration & Reference | ||
|
||
Variable declaration and variable referencing shares a identical syntax. | ||
|
||
Variable name must starts with `$` but `$` is not part of the name. | ||
|
||
```ps1 | ||
$var = 'foo' | ||
echo $var | ||
``` | ||
|
||
## Scope |
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
29 changes: 29 additions & 0 deletions
29
docs/document/Powershell/docs/Object Manipulation/Extended Type System.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Extended Type System | ||
|
||
Extended Type System(ETS) is for consistent experience with **some** `.NET` types when working with Powershell. | ||
|
||
For this purpose, Powershell wraps the traget object as `PSObject` with two approaches: | ||
|
||
- Set the object to be wrapped as a meta object(similar to lua metatable) | ||
- Add extra members to the containing `PSObject` itself. | ||
|
||
A common example would be `Process` type. | ||
|
||
```ps1 | ||
(gps | select -First 1).GetType().Name # Process | ||
(gps | select -First 1) -is [PSObject] # True | ||
(gps | select -First 1) -is [PSCustomObject] # True | ||
# -is checks underlying type too | ||
(gps | select -First 1) -is [System.Diagnostics.Process] # True | ||
``` | ||
|
||
The functionality of ETS achieved benifits: | ||
|
||
- Allow custom behaviours like formatting, sorting for your custom type or object. | ||
- Dynamic interpreting a `HashTable` to any `PSObject` | ||
- Accessibility to the underlying object. | ||
- Manipulation on extended members. | ||
|
||
## ETS Members | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
docs/document/Powershell/docs/Object Manipulation/ForEach.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ForEach | ||
|
||
> [!TIP] | ||
> Use `foreach` or `%` alias for `ForEach-Object`. | ||
## Works like Select | ||
|
||
`ForEach-Object` can do the same thing as `Select-Object -ExpandProperty`. | ||
|
||
```ps1 | ||
gci | foreach Name | ||
# or | ||
gci | foreach { $_.Name } | ||
# equivalent to | ||
gci | select -ExpandProperty Name | ||
``` | ||
|
||
The way `ForEach-Object` behaves is collecting implicitly returned values as an array. Every implicitly returned value will be collected as a item. | ||
|
||
```ps1 | ||
gci | foreach { $_.Exists, $false } # True, False, True, False... | ||
``` | ||
|
||
If you do want a `$null` return, use `Out-Null` to swallow the value. | ||
|
||
```ps1 | ||
# doesn't make much sense though | ||
(gci | foreach { $_.Name | Out-Null }) -eq $null # True | ||
``` | ||
|
File renamed without changes.
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
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