diff --git a/src/Common/Commands.Common/AzureLongRunningJob.cs b/src/Common/Commands.Common/AzureLongRunningJob.cs index 1d1f61314cb0..0652e289a5f5 100644 --- a/src/Common/Commands.Common/AzureLongRunningJob.cs +++ b/src/Common/Commands.Common/AzureLongRunningJob.cs @@ -191,11 +191,13 @@ public override string StatusMessage returnValue.MyInvocation.BoundParameters.Add(parameter.Key, parameter.Value); } - foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) + + foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { field.SafeCopyValue(source: cmdlet, target: returnValue); } + cmdlet.SafeCopyParameterSet(returnValue); return returnValue as U; } @@ -829,6 +831,9 @@ private bool InvokeShouldMethodAndWaitForResults(Func shouldMethod } } + /// + /// Stop job execution + /// public override void StopJob() { ShouldMethodStreamItem stream; diff --git a/src/Common/Commands.Common/Extensions/CmdletExtensions.cs b/src/Common/Commands.Common/Extensions/CmdletExtensions.cs index a93c4e0021f5..8d09a038932f 100644 --- a/src/Common/Commands.Common/Extensions/CmdletExtensions.cs +++ b/src/Common/Commands.Common/Extensions/CmdletExtensions.cs @@ -178,6 +178,30 @@ public static void SafeCopyValue(this FieldInfo field, T source, T target) } } + /// + /// Safely copy the selected parameter set from one cmdlet to another + /// + /// The cmdlet type + /// The cmdlet to copy the parameter set name from + /// The cmdlet to copy to + public static void SafeCopyParameterSet(this T source, T target) where T: AzurePSCmdlet + { + if (source != null && target != null) + { + if (!string.IsNullOrWhiteSpace(source.ParameterSetName)) + { + try + { + target.SetParameterSet(source.ParameterSetName); + } + catch + { + + } + } + } + } + public static string AsAbsoluteLocation(this string realtivePath) { return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath));