Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ class BookList {
# Static method to initialize the list of books. Called in the other
# static methods to avoid needing to explicit initialize the value.
static [void] Initialize() { [BookList]::Initialize($false) }
static [bool] Initialize([bool]$force) {
if ([BookList]::Books.Count -gt 0 -and -not $force) {
static [bool] Initialize([bool]$Force) {
if ([BookList]::Books.Count -gt 0 -and -not $Force) {
return $false
}

Expand Down Expand Up @@ -527,7 +527,7 @@ module is removed, so are the type accelerators.

## Manually importing classes from a PowerShell module

`Import-Module` and the `#requires` statement only import the module functions,
`Import-Module` and the `#Requires` statement only import the module functions,
aliases, and variables, as defined by the module. Classes aren't imported.

If a module defines classes and enumerations but doesn't add type accelerators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class BaseExample {
Write-Verbose "[$($Type.Name)] static constructor"
}

static [void] ParamMessage([type]$Type, [object]$Value) {
static [void] ParamMessage([type]$Type, [Object]$Value) {
Write-Verbose "[$($Type.Name)] param constructor ($Value)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ declaration.
This example shows the basic PowerShell class inheritance syntax.

```powershell
Class Derived : Base {...}
class Derived : Base {...}
```

This example shows inheritance with an interface declaration coming after the
base class.

```powershell
Class Derived : Base, Interface {...}
class Derived : Base, Interface {...}
```

## Syntax
Expand Down Expand Up @@ -657,7 +657,7 @@ Kelvin. For any other format, the method should throw a
}
# If format provider isn't specified, use the current culture.
if ($null -eq $FormatProvider) {
$FormatProvider = [CultureInfo]::CurrentCulture
$FormatProvider = [cultureinfo]::CurrentCulture
}
# Format the temperature.
switch ($Format) {
Expand Down Expand Up @@ -748,7 +748,7 @@ class Temperature : System.IFormattable {
}
# If format provider isn't specified, use the current culture.
if ($null -eq $FormatProvider) {
$FormatProvider = [CultureInfo]::CurrentCulture
$FormatProvider = [cultureinfo]::CurrentCulture
}
# Format the temperature.
switch ($Format) {
Expand Down Expand Up @@ -815,7 +815,7 @@ To implement the interface, the class needs to inherit from
method needs to have the following signature:

```powershell
[bool] Equals([object]$Other) {
[bool] Equals([Object]$Other) {
# Implementation
}
```
Expand All @@ -830,7 +830,7 @@ values to Kelvin, since temperatures can be equivalent even with different
scales.

```powershell
[bool] Equals([object]$Other) {
[bool] Equals([Object]$Other) {
# If the other object is null, we can't compare it.
if ($null -eq $Other) {
return $false
Expand All @@ -851,7 +851,7 @@ With the interface method implemented, the updated definition for
**Temperature** is:

```powershell
class Temperature : System.IFormattable, System.IEquatable[object] {
class Temperature : System.IFormattable, System.IEquatable[Object] {
[float] $Degrees
[TemperatureScale] $Scale

Expand Down Expand Up @@ -899,7 +899,7 @@ class Temperature : System.IFormattable, System.IEquatable[object] {
}
# If format provider isn't specified, use the current culture.
if ($null -eq $FormatProvider) {
$FormatProvider = [CultureInfo]::CurrentCulture
$FormatProvider = [cultureinfo]::CurrentCulture
}
# Format the temperature.
switch ($Format) {
Expand Down Expand Up @@ -927,7 +927,7 @@ class Temperature : System.IFormattable, System.IEquatable[object] {
return $this.ToString($null, $null)
}

[bool] Equals([object]$Other) {
[bool] Equals([Object]$Other) {
# If the other object is null, we can't compare it.
if ($null -eq $Other) {
return $false
Expand Down Expand Up @@ -999,7 +999,7 @@ converted to a different scale, is a floating point number, the method can rely
on the underlying type for the actual comparison.

```powershell
[int] CompareTo([object]$Other) {
[int] CompareTo([Object]$Other) {
# If the other object's null, consider this instance "greater than" it
if ($null -eq $Other) {
return 1
Expand All @@ -1021,7 +1021,7 @@ The final definition for the **Temperature** class is:
```powershell
class Temperature : System.IFormattable,
System.IComparable,
System.IEquatable[object] {
System.IEquatable[Object] {
# Instance properties
[float] $Degrees
[TemperatureScale] $Scale
Expand Down Expand Up @@ -1071,7 +1071,7 @@ class Temperature : System.IFormattable,
}
# If format provider isn't specified, use the current culture.
if ($null -eq $FormatProvider) {
$FormatProvider = [CultureInfo]::CurrentCulture
$FormatProvider = [cultureinfo]::CurrentCulture
}
# Format the temperature.
switch ($Format) {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ class Temperature : System.IFormattable,
return $this.ToString($null, $null)
}

[bool] Equals([object]$Other) {
[bool] Equals([Object]$Other) {
# If the other object is null, we can't compare it.
if ($null -eq $Other) {
return $false
Expand All @@ -1112,7 +1112,7 @@ class Temperature : System.IFormattable,
# Compare the temperatures as Kelvin.
return $this.ToKelvin() -eq $OtherTemperature.ToKelvin()
}
[int] CompareTo([object]$Other) {
[int] CompareTo([Object]$Other) {
# If the other object's null, consider this instance "greater than" it
if ($null -eq $Other) {
return 1
Expand Down Expand Up @@ -1182,7 +1182,7 @@ generic type as long as the type parameter is already defined at parse time.
```powershell
class ExampleStringList : System.Collections.Generic.List[string] {}

$List = [ExampleStringList]::New()
$List = [ExampleStringList]::new()
$List.AddRange([string[]]@('a','b','c'))
$List.GetType() | Format-List -Property Name, BaseType
$List
Expand Down Expand Up @@ -1243,7 +1243,7 @@ This time, PowerShell doesn't raise any errors. Both classes are now defined.
Run the following code block to view the behavior of the new class.

```powershell
$List = [ExampleItemList]::New()
$List = [ExampleItemList]::new()
$List.AddRange([ExampleItem[]]@(
[ExampleItem]@{ Name = 'Foo' }
[ExampleItem]@{ Name = 'Bar' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,17 @@ class. The representation for **DerivedClassB** is different because it
overrode the `ToString()` instance method.

```powershell
"`$base = [BaseClass]::New() => $($base = [BaseClass]::New(); $base)"
"`$a = [DerivedClassA]::New() => $($a = [DerivedClassA]::New(); $a)"
"`$b = [DerivedClassB]::New() => $($b = [DerivedClassB]::New(); $b)"
"`$c = [DerivedClassC]::New() => $($c = [DerivedClassC]::New(); $c)"
"`$base = [BaseClass]::new() => $($base = [BaseClass]::new(); $base)"
"`$a = [DerivedClassA]::new() => $($a = [DerivedClassA]::new(); $a)"
"`$b = [DerivedClassB]::new() => $($b = [DerivedClassB]::new(); $b)"
"`$c = [DerivedClassC]::new() => $($c = [DerivedClassC]::new(); $c)"
```

```Output
$base = [BaseClass]::New() => 11/6/2023 9:44:57 AM
$a = [DerivedClassA]::New() => 11/6/2023 9:44:57 AM
$b = [DerivedClassB]::New() => 2023-11-06
$c = [DerivedClassC]::New() => 11/6/2023 9:44:57 AM
$base = [BaseClass]::new() => 11/6/2023 9:44:57 AM
$a = [DerivedClassA]::new() => 11/6/2023 9:44:57 AM
$b = [DerivedClassB]::new() => 2023-11-06
$c = [DerivedClassC]::new() => 11/6/2023 9:44:57 AM
```

The next block calls the `SetTimeStamp()` instance method for each instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ C:\TechDocs\FindDocs.ps1
You can run any executable command using its full path. As a security feature,
PowerShell doesn't run executable commands, including PowerShell scripts and
native commands, unless the command is located in a path listed in the
`$env:Path` environment variable.
`$Env:PATH` environment variable.

To run an executable file that's in the current directory, specify the full
path or use the relative path `.\` to represent the current directory.
Expand All @@ -58,7 +58,7 @@ when it runs commands.
1. External executable files (including PowerShell script files)

Therefore, if you type `help`, PowerShell first looks for an alias named
`help`, then a function named `Help`, and finally a cmdlet named `Help`. It
`help`, then a function named `help`, and finally a cmdlet named `help`. It
runs the first `help` item that it finds.

For example, if your session contains a cmdlet and a function, both named
Expand Down Expand Up @@ -247,7 +247,7 @@ For example, the following command saves the `Map` function in the `$myMap`
variable and then uses the `Call` operator to run it.

```powershell
$myMap = (Get-Command -Name map -CommandType function)
$myMap = (Get-Command -Name map -CommandType Function)
& ($myMap)
```

Expand All @@ -273,7 +273,7 @@ first module found alphabetically.

If the cmdlet isn't loaded, PowerShell searches the installed modules and
autoloads the first module that contains the cmdlet and runs that cmdlet.
PowerShell searches for modules in each path defined in the `$env:PSModulePath`
PowerShell searches for modules in each path defined in the `$Env:PSModulePath`
environment variable. The paths are searched in the order that they're listed
in the variable. Within each path, the modules are searched in alphabetical
order. PowerShell uses the cmdlet from the first match it finds.
Expand All @@ -299,7 +299,7 @@ Import-Module -Name DateFunctions -Prefix ZZ

## Running external executables

On Windows. PowerShell treats the file extensions listed in the `$env:PATHEXT`
On Windows. PowerShell treats the file extensions listed in the `$Env:PATHEXT`
environment variable as executable files. Files that aren't Windows executables
are handed to Windows to process. Windows looks up the file association and
executes the default Windows Shell verb for the extension. For Windows to
Expand All @@ -312,7 +312,7 @@ to register the file handler. For more information, see the documentation for
the [ftype][04] command.

For PowerShell to see a file extension as executable in the current session,
you must add the extension to the `$env:PATHEXT` environment variable.
you must add the extension to the `$Env:PATHEXT` environment variable.

## See also

Expand Down
Loading