本文整理汇总了C#中System.Management.Automation.PSObject.GetStringSerializationSource方法的典型用法代码示例。如果您正苦于以下问题:C# PSObject.GetStringSerializationSource方法的具体用法?C# PSObject.GetStringSerializationSource怎么用?C# PSObject.GetStringSerializationSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.PSObject
的用法示例。
在下文中一共展示了PSObject.GetStringSerializationSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStringFromPSObject
private string GetStringFromPSObject(PSObject source)
{
PSPropertyInfo stringSerializationSource = source.GetStringSerializationSource(null);
string str = null;
if (stringSerializationSource != null)
{
object obj2 = stringSerializationSource.Value;
if (obj2 != null)
{
try
{
str = obj2.ToString();
}
catch (Exception exception)
{
CommandProcessorBase.CheckForSevereException(exception);
}
}
return str;
}
try
{
str = source.ToString();
}
catch (Exception exception2)
{
CommandProcessorBase.CheckForSevereException(exception2);
}
return str;
}
示例2: GetStringFromPSObject
/// <summary>
/// Gets the string from PSObject using the information from
/// types.ps1xml. This string is used for serializing the PSObject.
/// </summary>
///
/// <param name="source">
/// PSObject to be converted to string
/// </param>
///
/// <returns>
/// string value to use for serializing this PSObject.
/// </returns>
private string GetStringFromPSObject(PSObject source)
{
Dbg.Assert(source != null, "caller should have validated the information");
// check if we have a well known string serialization source
PSPropertyInfo serializationProperty = source.GetStringSerializationSource(null);
string result = null;
if (serializationProperty != null)
{
object val = serializationProperty.Value;
if (val != null)
{
try
{
// if we have a string serialization value, return it
result = val.ToString();
}
catch (Exception exception)
{
CommandProcessorBase.CheckForSevereException(exception);
}
}
}
else
{
try
{
// fall back value
result = source.ToString();
}
catch (Exception exception)
{
CommandProcessorBase.CheckForSevereException(exception);
}
}
return result;
}