示例#1
0
        private static void AddReflectionParameterInfo(InstalledCmdletInfo cmdlet, Dictionary<string, MAMLReader.ParameterHelpInfo> parameters)
        {
            var typeMetadata = new TypeMetadata(cmdlet.Type);
            typeMetadata.Load();

            foreach (var p in parameters)
            {
                ParameterMetadata metadata;
                if (typeMetadata.Parameters.TryGetValue(p.Key.ToLowerInvariant(), out metadata))
                {
                    p.Value.Aliases = metadata.Aliases.ToArray();
                }
            }
        }
示例#2
0
        private static void AddReflectionCmdletInfo(InstalledCmdletInfo cmdlet)
        {
            if (cmdlet.Info == null)
            {
                var typeMetadata = new TypeMetadata(cmdlet.Type);
                typeMetadata.Load();

                cmdlet.Info = new MAMLReader.CommandHelpInfo { Name = cmdlet.CommandName, Keys = cmdlet.Keys };

                if (typeMetadata.ParameterSets != null && typeMetadata.ParameterSets.Count > 0)
                {
                    foreach (var pSet in typeMetadata.ParameterSets)
                    {
                        var psetInfo = new MAMLReader.ParameterSetHelpInfo();
                        cmdlet.Info.ParameterSets.Add(psetInfo);
                        psetInfo.Parameters.AddRange(pSet.Parameters
                            .Select(p => new MAMLReader.ParameterHelpInfo
                            {
                                Name = p.Name,
                                Aliases = p.Aliases != null ? p.Aliases.ToArray() : null,
                                IsMandatory = p.IsMandatory,
                                Position = p.Position,
                                Type = p.ParameterType.Name
                            }));
                    }
                }
                else
                {
                    var psetInfo = new MAMLReader.ParameterSetHelpInfo();
                    cmdlet.Info.ParameterSets.Add(psetInfo);
                    psetInfo.Parameters.AddRange(typeMetadata.Parameters.Values.Where(p => !p.IsBuiltin)
                        .Select(p => new MAMLReader.ParameterHelpInfo
                        {
                            Name = p.Name,
                            Aliases = p.Aliases != null ? p.Aliases.ToArray() : null,
                            IsMandatory = p.IsMandatory(null),
                            Position = p.Position(null),
                            Type = p.ParameterType.Name
                        }));
                }
            }
        }