当前位置: 首页>>代码示例>>C#>>正文


C# CommandInfo.CreateGetCommandCopy方法代码示例

本文整理汇总了C#中CommandInfo.CreateGetCommandCopy方法的典型用法代码示例。如果您正苦于以下问题:C# CommandInfo.CreateGetCommandCopy方法的具体用法?C# CommandInfo.CreateGetCommandCopy怎么用?C# CommandInfo.CreateGetCommandCopy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandInfo的用法示例。


在下文中一共展示了CommandInfo.CreateGetCommandCopy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPSObjectFromCmdletInfo

        /// <summary>
        /// Generates a HelpInfo PSObject from a CmdletInfo object
        /// </summary>
        /// <param name="input">command info</param>
        /// <returns>HelpInfo PSObject</returns>
        internal static PSObject GetPSObjectFromCmdletInfo(CommandInfo input)
        {
            // Create a copy of commandInfo for GetCommandCommand so that we can generate parameter
            // sets based on Dynamic Parameters (+ optional arguments)
            CommandInfo commandInfo = input.CreateGetCommandCopy(null);

            PSObject obj = new PSObject();

            obj.TypeNames.Clear();
            obj.TypeNames.Add(String.Format(CultureInfo.InvariantCulture, "{0}#{1}#command", DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp, commandInfo.ModuleName));
            obj.TypeNames.Add(String.Format(CultureInfo.InvariantCulture, "{0}#{1}", DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp, commandInfo.ModuleName));
            obj.TypeNames.Add(DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp);
            obj.TypeNames.Add("CmdletHelpInfo");
            obj.TypeNames.Add("HelpInfo");

            if (commandInfo is CmdletInfo)
            {
                CmdletInfo cmdletInfo = commandInfo as CmdletInfo;
                bool common = false;
                bool commonWorkflow = false;
                if (cmdletInfo.Parameters != null)
                {
                    common = HasCommonParameters(cmdletInfo.Parameters);
                    commonWorkflow = ((cmdletInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow);
                }

                obj.Properties.Add(new PSNoteProperty("CommonParameters", common));
                obj.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
                AddDetailsProperties(obj, cmdletInfo.Name, cmdletInfo.Noun, cmdletInfo.Verb, TypeNameForDefaultHelp);
                AddSyntaxProperties(obj, cmdletInfo.Name, cmdletInfo.ParameterSets, common, commonWorkflow, TypeNameForDefaultHelp);
                AddParametersProperties(obj, cmdletInfo.Parameters, common, commonWorkflow, TypeNameForDefaultHelp);
                AddInputTypesProperties(obj, cmdletInfo.Parameters);
                AddRelatedLinksProperties(obj, commandInfo.CommandMetadata.HelpUri);

                try
                {
                    AddOutputTypesProperties(obj, cmdletInfo.OutputType);
                }
                catch (PSInvalidOperationException)
                {
                    AddOutputTypesProperties(obj, new ReadOnlyCollection<PSTypeName>(new List<PSTypeName>()));
                }

                AddAliasesProperties(obj, cmdletInfo.Name, cmdletInfo.Context);

                if (HasHelpInfoUri(cmdletInfo.Module, cmdletInfo.ModuleName))
                {
                    AddRemarksProperties(obj, cmdletInfo.Name, cmdletInfo.CommandMetadata.HelpUri);
                }
                else
                {
                    obj.Properties.Add(new PSNoteProperty("remarks", HelpDisplayStrings.None));
                }

                obj.Properties.Add(new PSNoteProperty("PSSnapIn", cmdletInfo.PSSnapIn));
            }
            else if (commandInfo is FunctionInfo)
            {
                FunctionInfo funcInfo = commandInfo as FunctionInfo;
                bool common = HasCommonParameters(funcInfo.Parameters);
                bool commonWorkflow = ((commandInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow);

                obj.Properties.Add(new PSNoteProperty("CommonParameters", common));
                obj.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", commonWorkflow));
                AddDetailsProperties(obj, funcInfo.Name, String.Empty, String.Empty, TypeNameForDefaultHelp);
                AddSyntaxProperties(obj, funcInfo.Name, funcInfo.ParameterSets, common, commonWorkflow, TypeNameForDefaultHelp);
                AddParametersProperties(obj, funcInfo.Parameters, common, commonWorkflow, TypeNameForDefaultHelp);
                AddInputTypesProperties(obj, funcInfo.Parameters);
                AddRelatedLinksProperties(obj, funcInfo.CommandMetadata.HelpUri);

                try
                {
                    AddOutputTypesProperties(obj, funcInfo.OutputType);
                }
                catch (PSInvalidOperationException)
                {
                    AddOutputTypesProperties(obj, new ReadOnlyCollection<PSTypeName>(new List<PSTypeName>()));
                }

                AddAliasesProperties(obj, funcInfo.Name, funcInfo.Context);

                if (HasHelpInfoUri(funcInfo.Module, funcInfo.ModuleName))
                {
                    AddRemarksProperties(obj, funcInfo.Name, funcInfo.CommandMetadata.HelpUri);
                }
                else
                {
                    obj.Properties.Add(new PSNoteProperty("remarks", HelpDisplayStrings.None));
                }
            }

            obj.Properties.Add(new PSNoteProperty("alertSet", null));
            obj.Properties.Add(new PSNoteProperty("description", null));
            obj.Properties.Add(new PSNoteProperty("examples", null));
            obj.Properties.Add(new PSNoteProperty("Synopsis", commandInfo.Syntax));
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:DefaultCommandHelpObjectBuilder.cs


注:本文中的CommandInfo.CreateGetCommandCopy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。