Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Last active June 22, 2024 05:49
Show Gist options
  • Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/9aa6b72f3519dbc71f7d0497df00eeb1 to your computer and use it in GitHub Desktop.

Revisions

  1. refactorsaurusrex revised this gist Oct 16, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion appendAllLines.ps1
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ $output = 'This is an output string'
    [System.IO.File]::AppendAllLines($path, $output)
    # Result: 'Cannot find an overload for "AppendAllLines" and the argument count: "2".'

    # However, if your parameters are strongly typed, the method will resolve correctly:
    # However, if you cast the string to an array, the correct overload can be found:
    [System.IO.File]::AppendAllLines([string]$path, [string[]]$output)

    # Hooray!
  2. refactorsaurusrex revised this gist Jul 5, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions appendAllLines.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    $path = 'C:\text.txt'
    $output = "This is an output string"
    $output = 'This is an output string'

    # This works...
    [System.IO.File]::WriteAllLines($path, $output)
    @@ -9,4 +9,6 @@ $output = "This is an output string"
    # Result: 'Cannot find an overload for "AppendAllLines" and the argument count: "2".'

    # However, if your parameters are strongly typed, the method will resolve correctly:
    [System.IO.File]::AppendAllLines([string]$path, [string[]]$output)
    [System.IO.File]::AppendAllLines([string]$path, [string[]]$output)

    # Hooray!
  3. refactorsaurusrex created this gist Jul 5, 2017.
    12 changes: 12 additions & 0 deletions appendAllLines.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    $path = 'C:\text.txt'
    $output = "This is an output string"

    # This works...
    [System.IO.File]::WriteAllLines($path, $output)

    # But this doesn't. WTF!
    [System.IO.File]::AppendAllLines($path, $output)
    # Result: 'Cannot find an overload for "AppendAllLines" and the argument count: "2".'

    # However, if your parameters are strongly typed, the method will resolve correctly:
    [System.IO.File]::AppendAllLines([string]$path, [string[]]$output)