-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved the script #73
base: main
Are you sure you want to change the base?
Conversation
Changed the function name to PowerShell valid function name syntax Added proper error types to the throw statements Changed some variable types to full types instead of using type accelerators
@microsoft-github-policy-service agree |
$bytes = [System.Text.Encoding]::Unicode.GetBytes($cmdLine) | ||
[Convert]::ToBase64String($bytes) | ||
} | ||
function ConvertTo-Base64EncodedString([System.String]$cmdLine) { |
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.
Why not use [string]
, the builtin type?
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.
Because it eliminates confusion when we explicitly type out the fully qualified type name instead of using type accelerator/alias.
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.
I understand the other argument (in fact it's a fantastic one!), but this one seems to be just an opinion. (It's easily countered with "How does it eliminate confusion?", etc., for instance.) I'm not really meaning to press this further, however.
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.
The confusion elimination is by being explicit instead of implicit
like in this example
$CSharpCode = @'
namespace MyNamespace
{
public class String
{
public string Value { get; set; }
}
}
'@
Add-Type -TypeDefinition $CSharpCode
Set-Alias -Name String -Value MyNamespace.String
$myStringObject = [String]::new()
$myStringObject.Value = 'Hello'
$myStringObject.Value
That doesn't work unless i disambiguate it by using this
$myStringObject = [MyNamespace.String]::new()
since both System and my custom namespace have the same String class.
\s+$
in VS Code's search as regex.