mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2026-03-20 08:59:10 +00:00
IODevice.Set readability
manual and pester tests pass
This commit is contained in:
parent
91e798caa1
commit
68cf0cef37
35
lib/io.ps1
35
lib/io.ps1
@ -146,21 +146,34 @@ class IODevice : IRemote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[void] Set ([PSObject]$device) {
|
[void] Set ([PSObject]$device) {
|
||||||
$v = $device.IsOutput -eq ($this.kindOfDevice -eq 'Output')
|
$required = 'IsOutput', 'Driver', 'Name'
|
||||||
|
$missing = $required | Where-Object { $null -eq $device.PSObject.Properties[$_] }
|
||||||
|
|
||||||
|
if ($missing) {
|
||||||
|
throw [System.ArgumentException]::new(("Invalid device object. Missing member(s): {0}" -f ($missing -join ', ')), 'device')
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectsOutput = ($this.kindOfDevice -eq 'Output')
|
||||||
|
if ([bool]$device.IsOutput -ne $expectsOutput) {
|
||||||
|
throw [System.ArgumentException]::new(("Device direction mismatch. Expected IsOutput={0}." -f $expectsOutput), 'device')
|
||||||
|
}
|
||||||
|
|
||||||
$d = $device.Driver
|
$d = $device.Driver
|
||||||
$n = $device.Name
|
$n = $device.Name
|
||||||
|
|
||||||
if ($v -and $d -is [string] -and $n -is [string]) {
|
if (-not ($d -is [string])) {
|
||||||
if ($d -eq '' -and $n -eq '') {
|
throw [System.ArgumentException]::new('Invalid device object. Driver must be a string.', 'device')
|
||||||
$this.Clear()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ($d -in $this.drivers.Values) {
|
|
||||||
$this.Setter($d, $n)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Write-Warning "Invalid device object provided to Set method."
|
if (-not ($n -is [string])) {
|
||||||
|
throw [System.ArgumentException]::new('Invalid device object. Name must be a string.', 'device')
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($d -eq '' -and $n -eq '') { $this.Clear(); return }
|
||||||
|
if ($d -notin $this.drivers.Values) {
|
||||||
|
throw [System.ArgumentOutOfRangeException]::new('device.Driver', $d, 'Invalid device driver provided to Set method.')
|
||||||
|
}
|
||||||
|
|
||||||
|
$this.Setter($d, $n)
|
||||||
}
|
}
|
||||||
|
|
||||||
[void] Clear () {
|
[void] Clear () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user