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


C# PSObject.ToString方法代码示例

本文整理汇总了C#中System.Management.Automation.PSObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PSObject.ToString方法的具体用法?C# PSObject.ToString怎么用?C# PSObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.PSObject的用法示例。


在下文中一共展示了PSObject.ToString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindArguments

 internal override void BindArguments(PSObject obj)
 {
     if (obj != null)
     {
         var inputObject = obj.ToString();
         _process.StandardInput.WriteLine(inputObject);
     }
 }
开发者ID:stangelandcl,项目名称:Pash,代码行数:8,代码来源:ApplicationProcessor.cs

示例2: ProcessRecord

        public IEnumerable<String> ProcessRecord(PSObject record)
        {
            if (record == null)
            {
                yield break;
            }

            if (_raw)
            {
                yield return record.ToString();
            }
            else
            {
                if (_pipeline == null)
                {
                    _pipeline = CreatePipeline();
                    _pipeline.InvokeAsync();
                }

                _pipeline.Input.Write(record);

                foreach (PSObject result in _pipeline.Output.NonBlockingRead())
                {
                    yield return result.ToString();
                }
            }
        }
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:OutStringFormatter.cs

示例3: FormatCommandResult

        private static string FormatCommandResult(PSObject psObject)
        {
            var result = string.Join(Environment.NewLine,
                                     psObject.ToString()
                                             .Split('\n')
                                             .Select(row => row.TrimEnd())

                );
            return result;
        }
开发者ID:sebastianhallen,项目名称:Goose,代码行数:10,代码来源:PowerShellCommandRunner.cs

示例4: GenerateOutOfBandObjectAsToString

 internal static FormatEntryData GenerateOutOfBandObjectAsToString(PSObject so)
 {
     FormatEntryData data = new FormatEntryData {
         outOfBand = true
     };
     RawTextFormatEntry entry = new RawTextFormatEntry {
         text = so.ToString()
     };
     data.formatEntryInfo = entry;
     return data;
 }
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:OutOfBandFormatViewManager.cs

示例5: GenerateOutOfBandObjectAsToString

        internal static FormatEntryData GenerateOutOfBandObjectAsToString(PSObject so)
        {
            FormatEntryData fed = new FormatEntryData();
            fed.outOfBand = true;

            RawTextFormatEntry rawTextEntry = new RawTextFormatEntry();
            rawTextEntry.text = so.ToString();
            fed.formatEntryInfo = rawTextEntry;

            return fed;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:11,代码来源:FormatViewManager.cs

示例6: GenerateSimpleFormatEntry

 public virtual SimpleFormatEntryData GenerateSimpleFormatEntry(PSObject data)
 {
     return new SimpleFormatEntryData(Shape, data.ToString()) {
         WriteToErrorStream = data.WriteToErrorStream
     };
 }
开发者ID:prateek,项目名称:Pash,代码行数:6,代码来源:FormatGenerator.cs

示例7: SmartToString

        /// <summary>
        /// helper to convert an PSObject into a string
        /// It takes into account enumerations (use display name)
        /// </summary>
        /// <param name="so">shell object to process</param>
        /// <param name="expressionFactory">expression factory to create MshExpression</param>
        /// <param name="enumerationLimit">limit on IEnumerable enumeration</param>
        /// <param name="formatErrorObject">stores errors during string conversion</param>
        /// <returns>string representation</returns>
        internal static string SmartToString(PSObject so, MshExpressionFactory expressionFactory, int enumerationLimit, StringFormatError formatErrorObject)
        {
            if (so == null)
                return "";

            try
            {
                IEnumerable e = PSObjectHelper.GetEnumerable(so);
                if (e != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");

                    bool first = true;
                    int enumCount = 0;
                    IEnumerator enumerator = e.GetEnumerator();
                    if (enumerator != null)
                    {
                        IBlockingEnumerator<object> be = enumerator as IBlockingEnumerator<object>;
                        if (be != null)
                        {
                            while (be.MoveNext(false))
                            {
                                if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                                {
                                    throw new PipelineStoppedException();
                                }
                                if (enumerationLimit >= 0)
                                {
                                    if (enumCount == enumerationLimit)
                                    {
                                        sb.Append(ellipses);
                                        break;
                                    }
                                    enumCount++;
                                }

                                if (!first)
                                {
                                    sb.Append(", ");
                                }
                                sb.Append(GetObjectName(be.Current, expressionFactory));
                                if (first)
                                    first = false;
                            }
                        }
                        else
                        {
                            foreach (object x in e)
                            {
                                if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                                {
                                    throw new PipelineStoppedException();
                                }
                                if (enumerationLimit >= 0)
                                {
                                    if (enumCount == enumerationLimit)
                                    {
                                        sb.Append(ellipses);
                                        break;
                                    }
                                    enumCount++;
                                }

                                if (!first)
                                {
                                    sb.Append(", ");
                                }
                                sb.Append(GetObjectName(x, expressionFactory));
                                if (first)
                                    first = false;
                            }
                        }
                    }
                    sb.Append("}");
                    return sb.ToString();
                }

                // take care of the case there is no base object
                return so.ToString();
            }
            catch (ExtendedTypeSystemException e)
            {
                // NOTE: we catch all the exceptions, since we do not know
                // what the underlying object access would throw
                if (formatErrorObject != null)
                {
                    formatErrorObject.sourceObject = so;
                    formatErrorObject.exception = e;
                }
                return "";
//.........这里部分代码省略.........
开发者ID:dfinke,项目名称:powershell,代码行数:101,代码来源:MshObjectUtil.cs

示例8: SerializePSObject

 private string SerializePSObject(PSObject psObject)
 {
     // handle some trivial cases
     if ((psObject == null) || (psObject.BaseObject == null))
     {
         return null;
     }
     // convert the base object to a string based on its type
     var baseType = psObject.BaseObject.GetType();
     if (baseType == typeof(Hashtable))
     {
         var value = new System.Text.StringBuilder();
         foreach (DictionaryEntry dictionaryEntry in (Hashtable)psObject.BaseObject)
         {
             value.AppendFormat("{0} = {1}\n", dictionaryEntry.Key, dictionaryEntry.Value);
         }
         return value.ToString();
     }
     else
     {
         return psObject.ToString();
     }
 }
开发者ID:mikeclayton,项目名称:AutoBot,代码行数:23,代码来源:PowerShellAgent.cs

示例9: GetSingle

      private PSObject GetSingle(string caption, string message, string prompt, string help, PSObject psDefault, Type type)
      {
         if (null != type && type.Equals(typeof(PSCredential)))
         {
            return PSObject.AsPSObject(((IPSConsole)this).PromptForCredential(caption, message, String.Empty, prompt));
         }

         while(true)
         {
            // TODO: Only show the help message if they type '?' as their entry something, in which case show help and re-prompt.
            if (!String.IsNullOrEmpty(help))
               ((IPSConsole) this).WriteLine(_brushes.ConsoleColorFromBrush(_brushes.VerboseForeground), _brushes.ConsoleColorFromBrush(_brushes.VerboseBackground), help);

            ((IPSConsole) this).Write(String.Format("{0}: ", prompt));

            if (null != type && typeof(SecureString).Equals(type))
            {
               var userData = ((IPSConsole) this).ReadLineAsSecureString() ?? new SecureString();
               return PSObject.AsPSObject(userData);
            } // Note: This doesn't look the way it does in PowerShell, but it should work :)
            else
            {
               if (psDefault != null && psDefault.ToString().Length > 0)
               {
                  if (Dispatcher.CheckAccess())
                  {
                     CurrentCommand = psDefault.ToString();
                     _commandBox.SelectAll();
                  }
                  else
                  {
                     Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action<string>) (def =>
                                                                                           {
                                                                                              CurrentCommand = def;
                                                                                              _commandBox.SelectAll();
                                                                                           }), psDefault.ToString());
                  }
               }

               var userData = ((IPSConsole) this).ReadLine();

               if (type != null && userData.Length > 0)
               {
                  object output;
                  var ice = TryConvertTo(type, userData, out output);
                  // Special exceptions that happen when casting to numbers and such ...
                  if (ice == null)
                  {
                     return PSObject.AsPSObject(output);
                  }
                  if ((ice.InnerException is FormatException) || (ice.InnerException is OverflowException))
                  {
                     ((IPSConsole)this).WriteErrorLine(
                        String.Format( @"Cannot recognize ""{0}"" as a {1} due to a format error.", userData, type.FullName )
                        );
                  }
                  else
                  {
                     return PSObject.AsPSObject(String.Empty);
                  }
               } 
               else if (userData.Length == 0)
               {
                      return PSObject.AsPSObject(String.Empty);
               } else return PSObject.AsPSObject(userData);
            }
         } 
      }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:68,代码来源:ConsoleControl.IPSConsole.cs

示例10: 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

示例11: 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

示例12: TranslatePSObjectToString

		internal static string TranslatePSObjectToString(PSObject pso, string format)
		{
			if (string.Equals(format, "xml", StringComparison.OrdinalIgnoreCase))
			{
				PSMemberInfoCollection<PSPropertyInfo> properties = pso.Properties;
				PSPropertyInfo pSPropertyInfo = properties.FirstOrDefault<PSPropertyInfo>((PSPropertyInfo item) => string.Equals(item.Name, "InnerXml", StringComparison.OrdinalIgnoreCase));
				if (pSPropertyInfo != null)
				{
					return pSPropertyInfo.Value.ToString();
				}
			}
			return pso.ToString();
		}
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:PipelineInvocation.cs

示例13: SmartToString

 internal static string SmartToString(PSObject so, MshExpressionFactory expressionFactory, int enumerationLimit, StringFormatError formatErrorObject)
 {
     if (so == null)
     {
         return "";
     }
     try
     {
         IEnumerable enumerable = GetEnumerable(so);
         if (enumerable != null)
         {
             StringBuilder builder = new StringBuilder();
             builder.Append("{");
             bool flag = true;
             int num = 0;
             IEnumerator enumerator = enumerable.GetEnumerator();
             if (enumerator != null)
             {
                 IBlockingEnumerator<object> enumerator2 = enumerator as IBlockingEnumerator<object>;
                 if (enumerator2 != null)
                 {
                     while (enumerator2.MoveNext(false))
                     {
                         if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                         {
                             throw new PipelineStoppedException();
                         }
                         if (enumerationLimit >= 0)
                         {
                             if (num == enumerationLimit)
                             {
                                 builder.Append("...");
                                 break;
                             }
                             num++;
                         }
                         if (!flag)
                         {
                             builder.Append(", ");
                         }
                         builder.Append(GetObjectName(enumerator2.Current, expressionFactory));
                         if (flag)
                         {
                             flag = false;
                         }
                     }
                 }
                 else
                 {
                     foreach (object obj2 in enumerable)
                     {
                         if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                         {
                             throw new PipelineStoppedException();
                         }
                         if (enumerationLimit >= 0)
                         {
                             if (num == enumerationLimit)
                             {
                                 builder.Append("...");
                                 break;
                             }
                             num++;
                         }
                         if (!flag)
                         {
                             builder.Append(", ");
                         }
                         builder.Append(GetObjectName(obj2, expressionFactory));
                         if (flag)
                         {
                             flag = false;
                         }
                     }
                 }
             }
             builder.Append("}");
             return builder.ToString();
         }
         return so.ToString();
     }
     catch (ExtendedTypeSystemException exception)
     {
         if (formatErrorObject != null)
         {
             formatErrorObject.sourceObject = so;
             formatErrorObject.exception = exception;
         }
         return "";
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:91,代码来源:PSObjectHelper.cs


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