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


C# PSObject.Copy方法代码示例

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


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

示例1: TransformView

 private PSObject TransformView(PSObject originalHelpObject)
 {
     if (this._viewTokenToAdd == HelpView.Default)
     {
         tracer.WriteLine("Detailed, Full, Examples are not selected. Constructing default view.", new object[0]);
         return originalHelpObject;
     }
     string str = this._viewTokenToAdd.ToString();
     PSObject obj2 = originalHelpObject.Copy();
     obj2.TypeNames.Clear();
     if (originalHelpObject.TypeNames.Count == 0)
     {
         string item = string.Format(CultureInfo.InvariantCulture, "HelpInfo#{0}", new object[] { str });
         obj2.TypeNames.Add(item);
         return obj2;
     }
     foreach (string str3 in originalHelpObject.TypeNames)
     {
         if (!str3.ToLower(CultureInfo.InvariantCulture).Equals("system.string") && !str3.ToLower(CultureInfo.InvariantCulture).Equals("system.object"))
         {
             string str4 = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", new object[] { str3, str });
             tracer.WriteLine("Adding type {0}", new object[] { str4 });
             obj2.TypeNames.Add(str4);
         }
     }
     foreach (string str5 in originalHelpObject.TypeNames)
     {
         tracer.WriteLine("Adding type {0}", new object[] { str5 });
         obj2.TypeNames.Add(str5);
     }
     return obj2;
 }
开发者ID:nickchal,项目名称:pash,代码行数:32,代码来源:GetHelpCommand.cs

示例2: TransformView

        /// <summary>
        /// Change <paramref name="originalHelpObject"/> as per user request.
        /// 
        /// This method creates a new type to the existing typenames 
        /// depending on Detailed,Full,Example parameters and adds this 
        /// new type(s) to the top of the list.
        /// </summary>
        /// <param name="originalHelpObject">Full help object to transform.</param>
        /// <returns>Transformed help object with new TypeNames.</returns>
        /// <remarks>If Detailed and Full are not specified, nothing is changed.</remarks>
        private PSObject TransformView(PSObject originalHelpObject)
        {
            Diagnostics.Assert(originalHelpObject != null,
                "HelpObject should not be null");

            if (_viewTokenToAdd == HelpView.Default)
            {
                s_tracer.WriteLine("Detailed, Full, Examples are not selected. Constructing default view.");
                return originalHelpObject;
            }

            string tokenToAdd = _viewTokenToAdd.ToString();
            // We are changing the types without modifying the original object.
            // The contract between help command and helpsystem does not 
            // allow us to modify returned help objects.
            PSObject objectToReturn = originalHelpObject.Copy();
            objectToReturn.TypeNames.Clear();

            if (originalHelpObject.TypeNames.Count == 0)
            {
                string typeToAdd = string.Format(CultureInfo.InvariantCulture, "HelpInfo#{0}", tokenToAdd);
                objectToReturn.TypeNames.Add(typeToAdd);
            }
            else
            {
                // User request at the top..
                foreach (string typeName in originalHelpObject.TypeNames)
                {
                    // dont add new types for System.String and System.Object..
                    // as they are handled differently for F&0..(bug935095)
                    if (typeName.ToLowerInvariant().Equals("system.string") ||
                        typeName.ToLowerInvariant().Equals("system.object"))
                    {
                        continue;
                    }

                    string typeToAdd = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", typeName, tokenToAdd);
                    s_tracer.WriteLine("Adding type {0}", typeToAdd);
                    objectToReturn.TypeNames.Add(typeToAdd);
                }

                // Existing typenames at the bottom..
                foreach (string typeName in originalHelpObject.TypeNames)
                {
                    s_tracer.WriteLine("Adding type {0}", typeName);
                    objectToReturn.TypeNames.Add(typeName);
                }
            }

            return objectToReturn;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:61,代码来源:HelpCommands.cs


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