@@ -20,7 +20,7 @@ PowerShell artifacts (such as DSC resources), and accelerate coverage of managem
2020- Debug types by using the PowerShell language
2121- Generate and handle exceptions by using formal mechanisms, and at the right level
2222
23- # Declare Base Class
23+ ## Declare Base Class
2424
2525You can declare a PowerShell class as a base type for another PowerShell class.
2626
@@ -53,7 +53,7 @@ $list.Add(100)
5353$list[0] # return 100
5454```
5555
56- # Call Base Class Constructor
56+ ### Call Base Class Constructor
5757
5858To call a base class constructor from a subclass, use the keyword ** base** :
5959
@@ -85,7 +85,7 @@ class C : B
8585}
8686```
8787
88- # Call Base Class Method
88+ ### Call Base Class Method
8989
9090You can override existing methods in subclasses. To do this, declare methods by using the same name
9191and signature:
@@ -137,7 +137,7 @@ $list.Add(100)
137137$list[0] # return 200
138138```
139139
140- # Declare Implemented Interface
140+ ### Declare Implemented Interface
141141
142142You can declare implemented interfaces after base types, or immediately after a colon (:), if there
143143is no base type specified. Separate all type names by using commas. It's similar to C# syntax.
@@ -160,11 +160,11 @@ class MyComparableBar : bar, system.IComparable
160160}
161161```
162162
163- # New language features in PowerShell 5.0
163+ ## New language features in PowerShell 5.0
164164
165165PowerShell 5.0 introduces the following new language elements in PowerShell:
166166
167- ## Class keyword
167+ ### Class keyword
168168
169169The ` class ` keyword defines a new class. This is a true .NET Framework type. Class members are
170170public, but only public within the module scope. You can't refer to the type name as a string (for
@@ -178,7 +178,7 @@ class MyClass
178178}
179179```
180180
181- ## Enum keyword and enumerations
181+ ### Enum keyword and enumerations
182182
183183Support for the ` enum ` keyword has been added, which uses newline as the delimiter. Currently, you
184184cannot define an enumerator in terms of itself. However, you can initialize an enum in terms of
@@ -212,12 +212,12 @@ enum SomeEnum { Max = 42 }
212212enum OtherEnum { Max = [SomeEnum]::Max + 1 }
213213```
214214
215- ## Import-DscResource
215+ ### Import-DscResource
216216
217217` Import-DscResource ` is now a true dynamic keyword. PowerShell parses the specified module's root
218218module, searching for classes that contain the ** DscResource** attribute.
219219
220- ## ImplementingAssembly
220+ ### ImplementingAssembly
221221
222222A new field, ** ImplementingAssembly** , has been added to ** ModuleInfo** . It is set to the dynamic
223223assembly created for a script module if the script defines classes, or the loaded assembly for
@@ -247,7 +247,7 @@ $s = "hello"
247247
248248All members are public.
249249
250- ## Constructors and instantiation
250+ ### Constructors and instantiation
251251
252252PowerShell classes can have constructors. They have the same name as their class. Constructors can
253253be overloaded. Static constructors are supported. Properties with initialization expressions are
@@ -256,7 +256,7 @@ body of a static constructor, and instance properties are initialized before the
256256non-static constructor. Currently, there is no syntax for calling a constructor from another
257257constructor (like the C\# syntax ": this()"). The workaround is to define a common ` Init() ` method.
258258
259- ### Creating instances
259+ #### Creating instances
260260
261261> [ !NOTE]
262262> In PowerShell 5.0, ` New-Object ` does not work with classes defined in PowerShell. Also, the type
@@ -288,7 +288,7 @@ The pseudo-static method `new()` works with .NET types, as shown in the followin
288288[hashtable]::new()
289289```
290290
291- ### Discovering constructors
291+ #### Discovering constructors
292292
293293You can now see constructor overloads with ` Get-Member ` , or as shown in this example:
294294
@@ -304,7 +304,7 @@ hashtable new(int capacity, float loadFactor)
304304` Get-Member -Static ` lists constructors, so you can view overloads like any other method. The
305305performance of this syntax is also considerably faster than ` New-Object ` .
306306
307- ## Methods
307+ ### Methods
308308
309309A PowerShell class method is implemented as a ** ScriptBlock** that has only an end block. All
310310methods are public. The following shows an example of defining a method named ** DoSomething** .
@@ -329,15 +329,15 @@ $b.DoSomething(42)
329329
330330Overloaded methods are also supported.
331331
332- ## Properties
332+ ### Properties
333333
334334All properties are public. Properties require either a newline or semicolon. If no object type is
335335specified, the property type is object.
336336
337337Properties that use validation or argument transformation attributes (like ` [ValidateSet("aaa")] ` )
338338work as expected.
339339
340- ## Hidden
340+ ### Hidden
341341
342342A new keyword, ` Hidden ` , has been added. ` Hidden ` can be applied to properties and methods
343343(including constructors).
@@ -349,17 +349,17 @@ the completion occurs in the class defining the hidden member.
349349A new attribute, ** System.Management.Automation.HiddenAttribute** has been added so that C\# code
350350can have the same semantics within PowerShell.
351351
352- ## Return types
352+ ### Return types
353353
354354Return type is a contract. The return value is converted to the expected type. If no return type is
355355specified, the return type is ** void** . There is no streaming of objects. Objects cannot be written
356356to the pipeline either intentionally or by accident.
357357
358- ## Attributes
358+ ### Attributes
359359
360360Two new attributes, ** DscResource** and ** DscProperty** have been added.
361361
362- ## Lexical scoping of variables
362+ ### Lexical scoping of variables
363363
364364The following shows an example of how lexical scoping works in this release.
365365
0 commit comments