예제 #1
0
        /// <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);
        }