diff --git a/Engine/VariableAnalysis.cs b/Engine/VariableAnalysis.cs index 5445df4bc..7c29c170f 100644 --- a/Engine/VariableAnalysis.cs +++ b/Engine/VariableAnalysis.cs @@ -86,7 +86,7 @@ private void ProcessParameters(IEnumerable parameters) type = paramAst.TypeName.GetReflectionType(); } - if (String.Equals(paramAst.TypeName.FullName, "switch", StringComparison.OrdinalIgnoreCase)) + if (paramAst.TypeName.GetReflectionType() == typeof(System.Management.Automation.SwitchParameter)) { isSwitchOrMandatory = true; } diff --git a/Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1 b/Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1 index 432dd1a91..ea436bb4f 100644 --- a/Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1 +++ b/Tests/Rules/AvoidGlobalOrUnitializedVarsNoViolations.ps1 @@ -31,6 +31,13 @@ $proc[0] function Test-PreferenceVariable { + Param( + [switch] + $a, + + [System.Management.Automation.SwitchParameter] + $b + ) if (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.GetVariableValue('VerbosePreference') -as @@ -38,4 +45,4 @@ function Test-PreferenceVariable } $VerbosePreference - } \ No newline at end of file +} \ No newline at end of file