-
Notifications
You must be signed in to change notification settings - Fork 1
/
to_merge_utils.ps1
59 lines (51 loc) · 1.61 KB
/
to_merge_utils.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[string[]]$NameList = 12, '34' # coerces to string
[object[]]$AnyList = 12, '34'
[Collections.Generic.List[string]]$list = 12, '34'
@{
ElementTypes = $List | ForEach-Object GetType | Join-String Name -sep ', '
SelfType = , $List | ForEach-Object GetType | Join-String Name -sep ', '
}
# hr
$list | ForEach-Object GetType | ForEach-Object Name
, $list | ForEach-Object GetType | ForEach-Object Name
# hr
[Collections.Generic.List[int]]$list = '3.14', 0x2345
# hr
$list | ForEach-Object GetType | ForEach-Object Name
, $list | ForEach-Object GetType | ForEach-Object Name
<#
Notebook utilites. Designed to be terse commands ran in notebooks. Ie: They don't follow best practices, or style guidelines
Currently not used in the examples because I didn't want to abstract things
making it harder to see what's going on.
#>
function str.Type {
<#
.synopsis
render an objects type as a short name
#>
param(
[switch]$WithNamespace,
[Parameter(Mandatory, ValueFromPipeline)]
$InputObject
)
process {
if ($null -eq $InputObject) { return '<trueNull>' }
# $tinfo = if($InputObject -is 'type') {
# $InputObject
# } else {
# ($InputObject)?.GetType()
# }
$tinfo = $InputObject.GetType()
if (-not $WithNamespace) {
return $tinfo.GetType().Name
}
# ((,$_.GetType()).ToString()) -replace '\bSystem\.', ''
# ((,$_.GetType()).ToString()) -replace '\bSystem\.', ''
}
}
'....'
$NameList | str.Type
str.Type $NameList
, $NameList | str.Type -WithNamespace
'....'
# $list.ToString()