GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve code style of Send-MailMessage cmdlet by ThreeFive-O · Pull Request #7723 · PowerShell/PowerShell

Conversation

@ThreeFive-O

@ThreeFive-O ThreeFive-O commented Sep 6, 2018

Copy link
Copy Markdown
Contributor

PR Summary

This PR should improve the code readability for the cmdlet, before any other work is started. Changes:

  • Change properties to auto properties
  • Improve code style as suggested by CodeFactor, mainly
    • Fix comment styling
    • Insert lines after statement with curly braces

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link:
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ThreeFive-O
Improve code style of Send-MailMessage cmdlet
7ee5d30
Change properties to auto properties
Fix comment  styling
Insert lines after statement with curly braces
@ThreeFive-O
ThreeFive-O requested review from James Truher (JamesWTruher), Paul Higinbotham (PaulHigin) and Dan Travison (dantraMSFT) as code owners September 6, 2018 16:21
@ThreeFive-O

ThreeFive-O commented Sep 6, 2018

Copy link
Copy Markdown
Contributor Author

Can those suppress message attributes be removed too? e.g.

[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Cc")]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]

Haven't seen them in newer cmdlets. I guess some artefacts from the original code base.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) approved these changes Sep 7, 2018
View reviewed changes

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs Outdated
}
}
private SwitchParameter _bodyashtml;
public SwitchParameter BodyAsHtml { get; set; } = false;

@iSazonov Ilya (iSazonov) Sep 7, 2018

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the init really needed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ThreeFive-O ThreeFive-O Sep 7, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really needed. It would be false anyway. Just make it more explicit. Same for the other inits.
I've seen it in other cmdlets and adopted this style.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@dantraMSFT Dan Travison (dantraMSFT) Sep 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, C# coding guidelines discourage initializing properties and fields to the default value. Thus, you don't initialize int to zero, references to null, and fields/properties to false. A SwitchParameter is a good example of this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@iSazonov
Ilya (iSazonov) requested a review from Rob Holt (rjmholt) September 7, 2018 09:07
@iSazonov Ilya (iSazonov) self-assigned this Sep 7, 2018
dantraMSFT
Dan Travison (dantraMSFT) approved these changes Sep 7, 2018
View reviewed changes

@dantraMSFT Dan Travison (dantraMSFT) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments/nits; otherwise, looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs Outdated
}
}
private SwitchParameter _bodyashtml;
public SwitchParameter BodyAsHtml { get; set; } = false;

@dantraMSFT Dan Travison (dantraMSFT) Sep 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, C# coding guidelines discourage initializing properties and fields to the default value. Thus, you don't initialize int to zero, references to null, and fields/properties to false. A SwitchParameter is a good example of this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Microsoft.PowerShell.Commands.Utility/commands/utility/Send-MailMessage.cs Outdated

/// <summary>
/// Specifies a value indicating whether the mail message body is in Html.
/// Gets or sets a value indicating whether the mail message body is in Html.

@dantraMSFT Dan Travison (dantraMSFT) Sep 7, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit... To be consistent with the other property summaries, use
'Gets or sets the value...'
versus
'Gets or set a value...'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ThreeFive-O
Remove unnecessary intializers from properties
6af4af8
Fix summary comment for BodyAsHtml
@ThreeFive-O

ThreeFive-O commented Sep 7, 2018

Copy link
Copy Markdown
Contributor Author

Dan Travison (@dantraMSFT) and Ilya (@iSazonov) Thank you for the review and the help.

  • Removed the initializers from the properties. For -Encoding paramater the initializer has to stay, because it will be null otherwise. Already present in the original code.
  • Fixed the summary to be in line with the other comments.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov
Ilya (iSazonov) merged commit dfe415e into PowerShell:master Sep 8, 2018
@ThreeFive-O
ThreeFive-O deleted the Improve-SendMailMessage-CodeStyle branch September 8, 2018 19:40
Travis Plunk (TravisEz13) pushed a commit that referenced this pull request Sep 10, 2018
@ThreeFive-O @TravisEz13
Improve code style of Send-MailMessage cmdlet (#7723)
e74bd73
@TravisEz13 Travis Plunk (TravisEz13) added this to the v6.1.0 milestone Sep 10, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@ThreeFive-O @iSazonov
Improve code style of Send-MailMessage cmdlet (PowerShell#7723)
bccad4a
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@ThreeFive-O @TravisEz13
Improve code style of Send-MailMessage cmdlet (PowerShell#7723)
a2b3031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov approved these changes
@JamesWTruher James Truher (JamesWTruher) Awaiting requested review from JamesWTruher
@PaulHigin Paul Higinbotham (PaulHigin) Awaiting requested review from PaulHigin
@rjmholt Rob Holt (rjmholt) Awaiting requested review from rjmholt
+1 more reviewer
@dantraMSFT Dan Travison (dantraMSFT) dantraMSFT approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@iSazonov Ilya (iSazonov)

Labels

None yet

Projects

None yet

Milestone

v6.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ThreeFive-O @dantraMSFT @iSazonov @TravisEz13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.