fix minor typos and config #6
@ -22,7 +22,7 @@ theme = "congo"
|
|||||||
bio = "A developer / DevOps guy fighting against corporate proxies."
|
bio = "A developer / DevOps guy fighting against corporate proxies."
|
||||||
links = [
|
links = [
|
||||||
{ email = "mailto:marco.blessing@googlemail.com" },
|
{ email = "mailto:marco.blessing@googlemail.com" },
|
||||||
# { link = "https://link-to-some-website.com/" },
|
{ link = "https://stackoverflow.com/users/5222635/ocram85/" },
|
||||||
# { amazon = "https://www.amazon.com/hz/wishlist/ls/wishlist-id" },
|
# { amazon = "https://www.amazon.com/hz/wishlist/ls/wishlist-id" },
|
||||||
# { apple = "https://www.apple.com" },
|
# { apple = "https://www.apple.com" },
|
||||||
# { codepen = "https://codepen.io/username" },
|
# { codepen = "https://codepen.io/username" },
|
||||||
|
@ -25,7 +25,7 @@ description = "A personal blog about PowerShell, Automation and more."
|
|||||||
showBreadcrumbs = false
|
showBreadcrumbs = false
|
||||||
showDraftLabel = true
|
showDraftLabel = true
|
||||||
showEdit = true
|
showEdit = true
|
||||||
editURL = "https://github.com/OCram85/Blog/"
|
editURL = "https://github.com/OCram85/Blog/edit/master/content/"
|
||||||
editAppendPath = true
|
editAppendPath = true
|
||||||
showHeadingAnchors = true
|
showHeadingAnchors = true
|
||||||
showPagination = true
|
showPagination = true
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
---
|
---
|
||||||
title: 'PowerShell Read Only Class Properties'
|
title: 'PowerShell Read Only Class Properties'
|
||||||
date: 2017-07-19T11:15:47+01:00
|
date: 2017-07-19T11:15:47+01:00
|
||||||
|
showDateUpdated: true
|
||||||
|
lastmod: 2022-01-11T14:37:54+01:00
|
||||||
draft: false
|
draft: false
|
||||||
|
|
||||||
|
categories: ['PowerShell']
|
||||||
|
tags: ['class', 'read-only', 'properties']
|
||||||
# lastmod: 2021-12-23T11:15:47+01:00
|
# lastmod: 2021-12-23T11:15:47+01:00
|
||||||
# showDateUpdated: true
|
# showDateUpdated: true
|
||||||
|
|
||||||
@ -351,7 +356,28 @@ And that's exactly what we wanted. We have hidden the the property `_Ready` and
|
|||||||
I personally like using _script properties_. But I take is on step further and create all public properties with a
|
I personally like using _script properties_. But I take is on step further and create all public properties with a
|
||||||
separate method:
|
separate method:
|
||||||
|
|
||||||
{% gist OCram85/d673764614438493afaa5cd413999436 AddPublicMember.ps1 %}
|
```powershell
|
||||||
|
hidden AddPublicMember() {
|
||||||
|
$Members = $this | Get-Member -Force -MemberType Property -Name '_*'
|
||||||
|
ForEach ($Member in $Members) {
|
||||||
|
$PublicPropertyName = $Member.Name -replace '_', ''
|
||||||
|
# Define getter part
|
||||||
|
$Getter = "return `$this.{0}" -f $Member.Name
|
||||||
|
$Getter = [ScriptBlock]::Create($Getter)
|
||||||
|
# Define setter part
|
||||||
|
$Setter = "Write-Warning 'This is a readonly property.'"
|
||||||
|
$Setter = [ScriptBlock]::Create($Setter)
|
||||||
|
|
||||||
|
$AddMemberParams = @{
|
||||||
|
Name = $PublicPropertyName
|
||||||
|
MemberType = 'ScriptProperty'
|
||||||
|
Value = $Getter
|
||||||
|
SecondValue = $Setter
|
||||||
|
}
|
||||||
|
$this | Add-Member @AddMemberParams
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
This avoids making errors if I work with multiple constructors. Without a method like `AddPublicMember` you are
|
This avoids making errors if I work with multiple constructors. Without a method like `AddPublicMember` you are
|
||||||
forced to define each public property in every constructor method.
|
forced to define each public property in every constructor method.
|
||||||
@ -360,6 +386,48 @@ All you have to do is to add the `AddPublicMember`method to your class definitio
|
|||||||
|
|
||||||
Finally our death start class looks like this:
|
Finally our death start class looks like this:
|
||||||
|
|
||||||
{{< gist OCram85 d673764614438493afaa5cd413999436>}}
|
```powershell
|
||||||
|
Class DeathStar {
|
||||||
|
[String]$Class = 'Space battle station'
|
||||||
|
[Int]$Width = '160000'
|
||||||
|
[String[]]$HyperDriveRating = @('Class 4', 'Class 20')
|
||||||
|
$Crew = @{
|
||||||
|
ImperialNavy = 342953
|
||||||
|
Stormtroopers = 25984
|
||||||
|
}
|
||||||
|
hidden [String]$_Ready = $null
|
||||||
|
|
||||||
So what do you think? - Feel free to discuss this in the comment section down below.
|
hidden AddPublicMember() {
|
||||||
|
$Members = $this | Get-Member -Force -MemberType Property -Name '_*'
|
||||||
|
ForEach ($Member in $Members) {
|
||||||
|
$PublicPropertyName = $Member.Name -replace '_', ''
|
||||||
|
# Define getter part
|
||||||
|
$Getter = "return `$this.{0}" -f $Member.Name
|
||||||
|
$Getter = [ScriptBlock]::Create($Getter)
|
||||||
|
# Define setter part
|
||||||
|
$Setter = "Write-Warning 'This is a readonly property.'"
|
||||||
|
$Setter = [ScriptBlock]::Create($Setter)
|
||||||
|
|
||||||
|
$AddMemberParams = @{
|
||||||
|
Name = $PublicPropertyName
|
||||||
|
MemberType = 'ScriptProperty'
|
||||||
|
Value = $Getter
|
||||||
|
SecondValue = $Setter
|
||||||
|
}
|
||||||
|
$this | Add-Member @AddMemberParams
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeathStar () {
|
||||||
|
$this.AddPublicMember()
|
||||||
|
$this._Ready = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
DeathStar ([int]$ImperialNavy, [int]$Stormtroopers) {
|
||||||
|
$this.AddPublicMember()
|
||||||
|
$this.Crew.ImperialNavy = $ImperialNavy
|
||||||
|
$this.Crew.StormTroopers = $Stormtroopers
|
||||||
|
$this._Ready = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: 'A Journey to the PowerShell Citadel'
|
title: 'A Journey to the PowerShell Citadel ✨🧙'
|
||||||
date: 2017-12-14T14:37:54+01:00
|
date: 2017-12-14T14:37:54+01:00
|
||||||
showDateUpdated: true
|
showDateUpdated: true
|
||||||
lastmod: 2021-12-22T14:37:54+01:00
|
lastmod: 2022-01-11T08:37:54+01:00
|
||||||
draft: false
|
draft: false
|
||||||
categories: ['PowerShell']
|
categories: ['PowerShell']
|
||||||
tags: ['resources']
|
tags: ['resources']
|
||||||
@ -14,7 +14,8 @@ draft: false
|
|||||||
## The Journey Begins Now Young Novice
|
## The Journey Begins Now Young Novice
|
||||||
|
|
||||||
In this section you find the most basic stuff. It's aimed to help beginners who just got in touch with PowerShell.
|
In this section you find the most basic stuff. It's aimed to help beginners who just got in touch with PowerShell.
|
||||||
All external links refer to the latest production ready PowerShell version. This is currently the version `5.1`.
|
All external links refer to the latest production ready PowerShell version.
|
||||||
|
This is currently the version `7.2.1 LTS`. If you're force to use PSSnapins you still have to use the version `5.1`.
|
||||||
|
|
||||||
### Docs
|
### Docs
|
||||||
|
|
||||||
@ -31,9 +32,9 @@ All external links refer to the latest production ready PowerShell version. This
|
|||||||
|
|
||||||
[official documentation]: https://docs.microsoft.com/en-us/powershell
|
[official documentation]: https://docs.microsoft.com/en-us/powershell
|
||||||
[docs.microsoft.com]: https://docs.microsoft.com
|
[docs.microsoft.com]: https://docs.microsoft.com
|
||||||
[powershell reference]: https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting?view=powershell-5.1
|
[powershell reference]: https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.2
|
||||||
[about pages]: https://docs.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_aliases?view=powershell-5.1
|
[about pages]: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-7.2
|
||||||
[the monad manifesto]: https://www.gitbook.com/book/devops-collective-inc/the-monad-manifesto-annotated/details
|
[the monad manifesto]: https://devops-collective-inc.gitbook.io/the-monad-manifesto-annotated/
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
You can also display the \_about\_ pages with a PowerShell function itself. To get a list of all about
|
You can also display the \_about\_ pages with a PowerShell function itself. To get a list of all about
|
||||||
@ -51,7 +52,7 @@ Google around or ask questions in communities like:
|
|||||||
- [PowerShell.org] - A very helpful and friendly community.
|
- [PowerShell.org] - A very helpful and friendly community.
|
||||||
|
|
||||||
[stackoverflow]: https://stackoverflow.com/questions/tagged/powershell
|
[stackoverflow]: https://stackoverflow.com/questions/tagged/powershell
|
||||||
[powershell.org]: https://powershell.org/forums
|
[powershell.org]: https://forums.powershell.org/
|
||||||
|
|
||||||
## Acolyte
|
## Acolyte
|
||||||
|
|
||||||
@ -93,20 +94,23 @@ In this phase you should also start working with additional tools like:
|
|||||||
- [Visual Studio Code](https://code.visualstudio.com/)
|
- [Visual Studio Code](https://code.visualstudio.com/)
|
||||||
- CI/CD Environments:
|
- CI/CD Environments:
|
||||||
- [Github](https://github.com/)
|
- [Github](https://github.com/)
|
||||||
- [Phabricator](https://www.phacility.com/phabricator/)
|
- [Gitea](https://gitea.io/)
|
||||||
- [Jenkins](https://jenkins.io/)
|
- [Drone](https://www.drone.io/)
|
||||||
- [AppVeyor](https://www.appveyor.com/)
|
- [AppVeyor](https://www.appveyor.com/)
|
||||||
- [GoCD](https://www.gocd.org/)
|
- [GoCD](https://www.gocd.org/)
|
||||||
- Helper
|
- Helper
|
||||||
- [ILSpy](http://ilspy.net/)
|
- [ILSpy](http://ilspy.net/)
|
||||||
- Coverage Reports
|
- Coverage Reports
|
||||||
- [Coveralls.io](https://coveralls.io/)
|
- [Coveralls.io](https://coveralls.io/)
|
||||||
|
- [Codecov](https://codecov.com)
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
If you develop open source projects I recommend using [Github](https://github.com/) in combination with
|
If you develop open source projects I recommend using [Github](https://github.com/) in combination with its
|
||||||
[AppVeyor](https://www.appveyor.com/). You don't need to maintain any additional infrastructure and they are free
|
[Actions](https://github.com/features/actions) feature or [Drone](https://www.drone.io/).
|
||||||
for public repositories. Otherwise I like working with Phabricator as _Git Server_ and project coordination.
|
You don't need to maintain any additional infrastructure and they are free for public repositories.
|
||||||
If you take this path you definitely need a build server like Jenkins.
|
Otherwise I like working with Gitea as _Git Server_ and project coordination. If you take this path you definitely
|
||||||
|
need a build server Drone. I definitely recommend running these as container in a Docker or even Kubernetes
|
||||||
|
environment.
|
||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
## Maester
|
## Maester
|
||||||
@ -121,16 +125,15 @@ spread the work of PowerShell while teaching others!
|
|||||||
Microsoft and PowerShell knowledge.
|
Microsoft and PowerShell knowledge.
|
||||||
- [DonJones.com] - If you never heard about DonJones I can't help you. He is one of the biggest
|
- [DonJones.com] - If you never heard about DonJones I can't help you. He is one of the biggest
|
||||||
maesters in the PowerShell citadel and a great inspiration.
|
maesters in the PowerShell citadel and a great inspiration.
|
||||||
- [Kevin Marquette on PowerShell Theory] - A great blog about various PowerShell
|
- [PowerShellExplained] - A great blog about various PowerShell topics by Kevin Marquette.
|
||||||
topics.
|
|
||||||
- [keithhill.wordpress.com] - One of the 4 maintainers of the [PowerShell Extension]
|
- [keithhill.wordpress.com] - One of the 4 maintainers of the [PowerShell Extension]
|
||||||
for [VS Code].
|
for [VS Code].
|
||||||
- [xainey.github.io] - Michael Willis blog contains great articles about PowerShell classes,
|
- [xainey.github.io] - Michael Willis blog contains great articles about PowerShell classes,
|
||||||
module creation and building frontend for PowerShell. It's high quality content and easy to follow expert topics.
|
module creation and building frontend for PowerShell. It's high quality content and easy to follow expert topics.
|
||||||
|
|
||||||
[dille.name]: http://dille.name
|
[dille.name]: http://dille.name
|
||||||
[donjones.com]: https://donjones.com/
|
[donjones.com]: https://donjones.com/powershell/
|
||||||
[kevin marquette on powershell theory]: https://kevinmarquette.github.io/
|
[powershellexplained]: https://powershellexplained.com/
|
||||||
[keithhill.wordpress.com]: http://rkeithhill.wordpress.com
|
[keithhill.wordpress.com]: http://rkeithhill.wordpress.com
|
||||||
[xainey.github.io]: https://xainey.github.io/
|
[xainey.github.io]: https://xainey.github.io/
|
||||||
[powershell extension]: https://github.com/PowerShell/vscode-powershell
|
[powershell extension]: https://github.com/PowerShell/vscode-powershell
|
||||||
@ -138,7 +141,7 @@ spread the work of PowerShell while teaching others!
|
|||||||
|
|
||||||
### Get in touch with the Archmaesters
|
### Get in touch with the Archmaesters
|
||||||
|
|
||||||
Take a look at the [PowerShell Slack Team](http://slack.poshcode.org/) if your searching other active PowerShell experts.
|
Take a look at the [PowerShell Slack Team](http://powershell.slack.com/) if your searching other active PowerShell experts.
|
||||||
|
|
||||||
## Additional Resources
|
## Additional Resources
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user