本文整理汇总了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;
}
示例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;
}