// Replaced with a DLR based binder - but code is preserved in case that approach doesn't // work well performance wise. // See if it's a value type being assigned and // make a copy if it is... private static object PreserveValueType(object value) { if (value == null) { return(null); } // Primitive types are immutable so just return them... Type valueType = value.GetType(); if (valueType.IsPrimitive) { return(value); } PSObject valueAsPSObject = value as PSObject; if (valueAsPSObject != null) { object baseObject = valueAsPSObject.BaseObject; if (baseObject != null) { valueType = baseObject.GetType(); if (valueType.IsValueType && !valueType.IsPrimitive) { return(valueAsPSObject.Copy()); } } } else if (valueType.IsValueType) { return(PSObject.CopyValueType(value)); } return(value); }
internal MamlCommandHelpInfo Copy() { MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), this.HelpCategory); return(result); }
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; }
/// <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; }