當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。