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);
        }
Example #2
0
        /// <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);
        }
 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;
 }
Example #4
0
        /// <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;
        }