Search Wiki:

UseRecommendedParameterTypes


TypeName UseRecommendedParameterTypes
CheckId PS1102
Error-Level Warning
Category Microsoft.PowerShell
Certainty 80%
BreakingChange Non-breaking
Cause A standard cmdlet parameter has a type that does not match parameter name.
Rule descriptionParameters that have standard names should use the parameter type that is typically associated with that parameter name. This rule uses regular expressions to detect commonly used parameter names. If it detects a regular expression match, the rule determines whether the value of the parameter is of the expected type, and it declares a rule violation if it is not. For more information and a list of standard parameter names and types, see "Common Parameter Names" on MSDN at http://go.microsoft.com/fwlink/?LinkID=182077. For more information about regular expressions, see ".NET Framework Regular Expressions" on MSDN at http://go.microsoft.com/fwlink/?LinkID=148954.
How to fix violations Change the type of the parameter to match the type recommended for the parameter name, or change the name of the parameter to indicate that it is different from the standard.
When to exclude warnings Do not suppress warnings from this rule.
Related rules (None)
See also FxCop Rules for Windows PowerShell

Examples


[Cmdlet("Write", "String")]
 public class WriteStringCommand : PSCmdlet
 {
     // Rule violation – non-standard parameter type.
     // To fix, use Int32 type recommended with “TimeOut”
     // name.
     [Parameter]
     public TimeSpan TimeOut
     {
       get { return TimeSpan.FromMilliseconds(this.timeout);
           }
       set { this.timeout = (int)value.TotalMilliseconds; }
           }
     private int timeout;
 
     // ...
 }

Back to FxCop Rules for Windows PowerShell.
Last edited Mar 26 2010 at 5:21 PM  by JuneB, version 2
Updating...
Page view tracker