forked from dfinke/ImportExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InferData.ps1
95 lines (76 loc) · 1.83 KB
/
InferData.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function Test-String{
param($p)
[PSCustomObject]@{
Test=$p -is [string]
DataType = "string"
}
}
function Test-Date {
param($p)
[datetime]$result = [datetime]::MinValue
[PSCustomObject]@{
Test=[datetime]::TryParse($p, [ref]$result)
DataType = "datetime"
}
}
function Test-Boolean {
param($p)
#[bool]$result = [bool]::FalseString
[bool]$result = $false
[PSCustomObject]@{
Test=[bool]::TryParse($p, [ref]$result)
DataType = "bool"
}
}
function Test-Number {
param($p)
[double]$result = [double]::MinValue
[PSCustomObject]@{
Test=[double]::TryParse($p, [ref]$result)
DataType = "double"
}
}
function Test-Integer {
param($p)
[int]$result = [int]::MinValue
[PSCustomObject]@{
Test=[int]::TryParse($p, [ref]$result)
DataType = "int"
}
}
$tests = [ordered]@{
TestBoolean = Get-Command Test-Boolean
TestInteger = Get-Command Test-Integer
TestNumber = Get-Command Test-Number
TestDate = Get-Command Test-Date
TestString = Get-Command Test-String
}
function Invoke-AllTests {
param(
$target,
[Switch]$OnlyPassing,
[Switch]$FirstOne
)
$resultCount=0
$tests.GetEnumerator() | ForEach {
$result=& $_.Value $target
$testResult = [PSCustomObject]@{
Test = $_.Key
Target = $target
Result = $result.Test
DataType= $result.DataType
}
if(!$OnlyPassing) {
$testResult
} elseif ($result.Test -eq $true) {
if($FirstOne) {
if($resultCount -ne 1) {
$testResult
$resultCount+=1
}
} else {
$testResult
}
}
}
}