当前位置: 首页>>代码示例>>C#>>正文


C# PSObject.GetStringSerializationSource方法代码示例

本文整理汇总了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;
 }
开发者ID:nickchal,项目名称:pash,代码行数:30,代码来源:CustomInternalSerializer.cs

示例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;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:50,代码来源:CustomSerialization.cs


注:本文中的System.Management.Automation.PSObject.GetStringSerializationSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。