Skip to content

Commit 50ed951

Browse files
committed
Merge pull request #286 from Azure/clu
Clu
2 parents 2f1df81 + 853e0d5 commit 50ed951

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

src/CLU/Microsoft.CLU/CommandBinder/CmdletBinderAndCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ private void BindDynamicParameters()
342342
// If Cmdlet instance support dynamic parameters then rerun the parser to bind dynamic parameters.
343343
_dynamicParameterBindInProgress = true;
344344
this.ParserSeekBeginAndRun();
345+
var psCmdlet = _cmdlet as PSCmdlet;
346+
if (psCmdlet != null)
347+
{
348+
// We need to add all dynamic parameters that were bound
349+
foreach (var boundParam in _cmdletMetadata.Instance.Parameters)
350+
{
351+
if (boundParam.Value.IsBound && boundParam.Value.IsDynamic && !psCmdlet.MyInvocation.BoundParameters.ContainsKey(boundParam.Value.Name))
352+
{
353+
psCmdlet.MyInvocation.BoundParameters[boundParam.Value.Name] = boundParam.Value;
354+
}
355+
}
356+
}
345357
_dynamicParameterBindInProgress = false;
346358
}
347359
}

src/CLU/Microsoft.CLU/Metadata/CmdletMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class CmdletMetadata
1717
/// <summary>
1818
/// The metadata information of the cmdlet instance.
1919
/// </summary>
20-
public InstanceMetadata Instance { get; set; }
20+
public InstanceMetadata Instance { get; private set; }
2121

2222
/// <summary>
2323
/// Creates an instance of CmdletMetadata.

src/CLU/Microsoft.CLU/Metadata/InstanceMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ReadOnlyCollection<CommandParameterSetInfo> ParameterSets
5151
}
5252
}
5353

54-
Dictionary<string, ParameterMetadata> _dynamicParameters;
54+
Dictionary<string, ParameterMetadata> _dynamicParameters = new Dictionary<string, ParameterMetadata>();
5555
/// <summary>
5656
/// Get dynamic parameter metadata dictionary. The key is name of the dynamic
5757
/// parameter and value is the dynamic parameter metadata.

src/CLU/Microsoft.CLU/System.Management.Automation/CmdletInfo.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Collections.ObjectModel;
1+
using Microsoft.CLU.Metadata;
2+
using System.Collections.ObjectModel;
23
using System.Linq;
34
using System.Reflection;
5+
using System.Collections.Generic;
46

57
namespace System.Management.Automation
68
{
@@ -25,6 +27,9 @@ internal CmdletInfo(Type cmdlet, PSModuleInfo module, ICommandRuntime runtime, s
2527
cmdlet.GetTypeInfo().GetCustomAttributes(typeof(OutputTypeAttribute), true)
2628
.Select(a => a as OutputTypeAttribute)
2729
.SelectMany(ot => ot.Type).ToList());
30+
31+
_typeMetadata = new TypeMetadata(cmdlet);
32+
_typeMetadata.Load();
2833
}
2934

3035
public string Noun
@@ -37,6 +42,13 @@ public string Verb
3742
get; private set;
3843
}
3944

45+
public override Dictionary<string, ParameterMetadata> Parameters
46+
{
47+
get
48+
{
49+
return _typeMetadata.Parameters;
50+
}
51+
}
4052
public override ReadOnlyCollection<PSTypeName> OutputType
4153
{
4254
get
@@ -67,6 +79,7 @@ public override string ToString()
6779
return Name;
6880
}
6981

82+
private TypeMetadata _typeMetadata;
7083
private ReadOnlyCollection<PSTypeName> _outputTypes;
7184
}
7285
}

src/CLU/Microsoft.CLU/System.Management.Automation/CommandInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public abstract class CommandInfo
88
public CommandTypes CommandType { get { return CommandTypes.Cmdlet; } }
99
public string Name { get; protected set; }
1010
public abstract ReadOnlyCollection<PSTypeName> OutputType { get; }
11-
public virtual Dictionary<string, ParameterMetadata> Parameters { get; private set; }
12-
public ReadOnlyCollection<CommandParameterSetInfo> ParameterSets { get; protected set; }
11+
public virtual Dictionary<string, ParameterMetadata> Parameters { get; }
12+
public ReadOnlyCollection<CommandParameterSetInfo> ParameterSets { get; }
1313
public PSModuleInfo Module { get; protected set; }
1414
public string ModuleName { get { return Module.Name; } }
1515

0 commit comments

Comments
 (0)