@@ -71,23 +71,6 @@ public static Job ExecuteAsJob<T>(this T cmdlet, string jobName, Action<T> execu
71
71
return job ;
72
72
}
73
73
74
- /// <summary>
75
- /// Determine if AsJob is present
76
- /// </summary>
77
- /// <typeparam name="T">The cmdlet type</typeparam>
78
- /// <param name="cmdlet">The cmdlet</param>
79
- /// <returns>True if the cmdlet shoudl run as a Job, otherwise false</returns>
80
- public static bool AsJobPresent < T > ( this T cmdlet ) where T : AzurePSCmdlet
81
- {
82
- if ( cmdlet == null )
83
- {
84
- throw new ArgumentNullException ( nameof ( cmdlet ) ) ;
85
- }
86
-
87
- return ( cmdlet . MyInvocation ? . BoundParameters != null
88
- && cmdlet . MyInvocation . BoundParameters . ContainsKey ( "AsJob" ) ) ;
89
- }
90
-
91
74
/// <summary>
92
75
/// Execute the given cmdlet synchronously os as a job, based on input parameters
93
76
/// </summary>
@@ -121,7 +104,8 @@ public static void ExecuteSynchronouslyOrAsJob<T>(this T cmdlet, Action<T> execu
121
104
throw new ArgumentNullException ( nameof ( executor ) ) ;
122
105
}
123
106
124
- if ( cmdlet . AsJobPresent ( ) )
107
+ // Since right now NoWait and AsJob are not in different parameter sets this check is necessary
108
+ if ( cmdlet . IsBound ( "AsJob" ) && ! cmdlet . IsBound ( "NoWait" ) )
125
109
{
126
110
cmdlet . WriteObject ( cmdlet . ExecuteAsJob ( cmdlet . ImplementationBackgroundJobDescription , executor ) ) ;
127
111
}
@@ -212,7 +196,7 @@ public static void SafeCopyParameterSet<T>(this T source, T target) where T : Az
212
196
/// <returns>true if the parameter was provided by the user, otherwise false</returns>
213
197
public static bool IsBound ( this PSCmdlet cmdlet , string parameterName )
214
198
{
215
- return cmdlet . MyInvocation . BoundParameters . ContainsKey ( parameterName ) ;
199
+ return cmdlet . MyInvocation ? . BoundParameters . ContainsKey ( parameterName ) ?? false ;
216
200
}
217
201
218
202
public static string AsAbsoluteLocation ( this string realtivePath )
@@ -358,7 +342,7 @@ public static List<T> ExecuteScript<T>(this PSCmdlet cmdlet, string contents)
358
342
public static bool IsParameterBound < TPSCmdlet , TProp > ( this TPSCmdlet cmdlet , Expression < Func < TPSCmdlet , TProp > > propertySelector ) where TPSCmdlet : PSCmdlet
359
343
{
360
344
var propName = ( ( MemberExpression ) propertySelector . Body ) . Member . Name ;
361
- return cmdlet . MyInvocation . BoundParameters . ContainsKey ( propName ) ;
345
+ return cmdlet . MyInvocation ? . BoundParameters . ContainsKey ( propName ) ?? false ;
362
346
}
363
347
364
348
#region PowerShell Commands
0 commit comments