X Tutup
The Wayback Machine - https://web.archive.org/web/20251011150933/https://github.com/PowerShell/PowerShell/issues/26149
Skip to content

SwitchParameter.IsPresent documentation does not match actual behavior when parameter is explicitly set to false #26149

@xtqqczze

Description

@xtqqczze

The inline documentation for the IsPresent property states that it returns true if the parameter was specified on the command line, and false otherwise:

/// <summary>
/// Returns true if the parameter was specified on the command line, false otherwise.
/// </summary>
/// <value>True if the parameter was specified, false otherwise</value>
public bool IsPresent
{
    get { return _isPresent; }
}

However, this description is inaccurate. The property returns false when a parameter is explicitly specified on the command line with a value of false.

Proposed Resolution

Either:

  1. Clarify documentation to specify that the property returns false both when the parameter is not specified and when it is explicitly specified with a value of false; or
  2. Adjust implementation so that IsPresent returns true whenever the parameter is explicitly supplied, regardless of its value.
  3. Deprecate IsPresent in favor of a clearer or more accurately named property that distinguishes between 'parameter presence' and 'parameter value'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup