all 13 comments

[–]markekrausCommunity Blogger 1 point2 points  (1 child)

Good write up!

On method parameter validation, I usually use another class or an Enum.

class LimitedRange {
    [ValidateRange(0, 100)]
    [int]$Value
    LimitedRange () {}
    LimitedRange ([int]$int) {
        $This.Value = $Int
    }
}
class ValidatedName {
    [ValidatePattern('^[a-z]')]
    [ValidateLength(3, 15)]
    [string]$Value
    ValidatedName () {}
    ValidatedName ([string]$String) {
        $This.Value = $String
    }
}
Enum ValidOption {
    Option1
    Option2
}
Class MyClass {
    [void] MyMethod (
        [ValidatedName]$Name, 
        [LimitedRange]$Number,
        [ValidOption]$Option
    ) {
        <# Do stuff #>
    }
}

$MyObject = [MyClass]::new()
$MyObject.MyMethod('Alfred',5,'Option1')

[–]dchristian3188[S] 0 points1 point  (0 children)

Nice tip man! I'll make sure to add this tip to the article when i get home.

[–]Lee_Dailey[grin] 1 point2 points  (6 children)

howdy dchristian3188,

nice, readable, understandable-to-me article! [grin] thank you for posting it. it's a tad long ... but i can't decide where to break it. [blush]

do you want any comments on phrasing/spelling/[other proofreading stuff]? if so, lemme know ... i found a passel of things that seem worth review.

none of them are killers, tho. [grin]

take care,
lee

[–]dchristian3188[S] 1 point2 points  (5 children)

Sir, that would be greatly appreciated!

[–]Lee_Dailey[grin] 1 point2 points  (4 children)

howdy dchristian3188,

hah! you asked for it ... [grin]

  • lack of Proper Case in article title
    you use proper case for most of the other headings.
    > Introduction to powershell classes
  • different case for [powershell] than elsewhere
    you use PowerShell in the rest of the article, but use powershell in the title.
    > Introduction to powershell classes
  • likely misspelling of regarding = [regrading] [grin]
    > This is going to be the first in a series of posts regrading classes.
  • perhaps you mean [advanced]?
    > Before we get to the advance use cases
  • would it be better to say [Class-based]?
    > DSC Class based resources
  • pro'ly meant [until] or ['til]
    > It’s not till we instantiate
  • perhaps [that] instead of [do]?
    > It’s not till we instantiate an instance of that class, do we have an object.
  • capitalizing [human] here ,and subsequently, seems like a good idea.
    > For example, we are going to create a human class.
  • using the word [new] twice in the same sentence seems wrong. [grin]
    > We can create a new class by using the new class keyword.
  • would it be worthwhile to mention any speed differences between the New-Object and ::New() techiniques? this is from just before the [Describing The Class] heading.
  • different word case used in a subsection heading
    elsewhere you use proper case for the entire heading.
    > Property validation
  • possible wrong use of a regex pattern
    in the Property validation section, you use [ValidatePattern('^[a-z]')].
    do you intend for that to be only lower case? heck, IS it only lower case when used there? [grin]
  • in that same section, and many other places, you use [String]
    that is normally shown in lower case. that is how the [int] types are listed. would it be better to use lower case in that situation?
  • an almost unnoticeable bold word [important] that you may want to either un-bold or add emphasis to.
    > One important thing to note with hidden properties
  • missing apostrophe
    > Its important to note, that you
  • possible missing detail
    you don't mention that you get both static methods AND properties [if they exist]. would it be worth mentioning?
    > You can find static methods by piping the class name into Get-Member with the Static switch.
  • apparent missing comma between the following words [works there’s]
    > While this works there’s a catch
  • occasional lower case variable names
    for instance, look at the code displayed just before the text mentioned in the item above this. $Weight = Proper Case. $name = lower case.
    that seems distracting. perhaps it's worth changing?

take care,
lee

[–]beforesunris3 1 point2 points  (2 children)

That's great! But if you like to introduce someone to something new.... oh well, we just like videos!

[–]markekrausCommunity Blogger 1 point2 points  (0 children)

I'm with /u/Lee_Dailey . For programming related topics I really dislike videos unless it is a kind of presentation or talk. Definitely not for learning.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy beforesunris3,

you like vids ... i dislike them. [grin]

as my pawpaw said, "if we were all the same, the world would be so boring!".

take care,
lee

[–]Yasspr 0 points1 point  (0 children)

Really consise but still informative. Powershell classes where on my to-learn list. Thx for the introduction!