Skip to content

Commit 2eedb8e

Browse files
committed
Fix usage of parameter sets in jobs
1 parent 9c141ae commit 2eedb8e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Common/Commands.Common/AzureLongRunningJob.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ public static U CopyCmdlet<U>(U cmdlet) where U : AzurePSCmdlet
191191
returnValue.MyInvocation.BoundParameters.Add(parameter.Key, parameter.Value);
192192
}
193193

194-
foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))
194+
195+
foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
195196
{
196197
field.SafeCopyValue(source: cmdlet, target: returnValue);
197198
}
198199

200+
cmdlet.SafeCopyParameterSet(returnValue);
199201
return returnValue as U;
200202
}
201203

@@ -829,6 +831,9 @@ private bool InvokeShouldMethodAndWaitForResults(Func<Cmdlet, bool> shouldMethod
829831
}
830832
}
831833

834+
/// <summary>
835+
/// Stop job execution
836+
/// </summary>
832837
public override void StopJob()
833838
{
834839
ShouldMethodStreamItem stream;

src/Common/Commands.Common/Extensions/CmdletExtensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ public static void SafeCopyValue<T>(this FieldInfo field, T source, T target)
178178
}
179179
}
180180

181+
/// <summary>
182+
/// Safely copy the selected parameter set from one cmdlet to another
183+
/// </summary>
184+
/// <typeparam name="T">The cmdlet type</typeparam>
185+
/// <param name="source">The cmdlet to copy the parameter set name from</param>
186+
/// <param name="target">The cmdlet to copy to</param>
187+
public static void SafeCopyParameterSet<T>(this T source, T target) where T: AzurePSCmdlet
188+
{
189+
if (source != null && target != null)
190+
{
191+
if (!string.IsNullOrWhiteSpace(source.ParameterSetName))
192+
{
193+
try
194+
{
195+
target.SetParameterSet(source.ParameterSetName);
196+
}
197+
catch
198+
{
199+
200+
}
201+
}
202+
}
203+
}
204+
181205
public static string AsAbsoluteLocation(this string realtivePath)
182206
{
183207
return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath));

0 commit comments

Comments
 (0)