MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using Dbg = System.Management.Automation.Diagnostics;5 6namespace System.Management.Automation.Host7{8 /// <summary>9 /// Provides a description of a choice for use by <see cref="System.Management.Automation.Host.PSHostUserInterface.PromptForChoice"/>.10 /// <!--Used by the engine to describe cmdlet parameters.-->11 /// </summary>12 public sealed13 class ChoiceDescription14 {15 #region DO NOT REMOVE OR RENAME THESE FIELDS - it will break remoting compatibility with Windows PowerShell compatibility with Windows PowerShell16 17 private readonly string label = null;18 private string helpMessage = string.Empty;19 20 #endregion21 22 /// <summary>23 /// Initializes an new instance of ChoiceDescription and defines the Label value.24 /// </summary>25 /// <param name="label">26 /// The label to identify this field description27 /// </param>28 /// <exception cref="System.Management.Automation.PSArgumentException">29 /// <paramref name="label"/> is null or empty.30 /// </exception>31 public32 ChoiceDescription(string label)33 {34 // the only required parameter is label.35 36 if (string.IsNullOrEmpty(label))37 {38 // "label" is not localizable39 throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label");40 }41 42 this.label = label;43 }44 45 /// <summary>46 /// Initializes an new instance of ChoiceDescription and defines the Label and HelpMessage values.47 /// </summary>48 /// <param name="label">49 /// The label to identify this field description.50 /// </param>51 /// <param name="helpMessage">52 /// The help message for this field.53 /// </param>54 /// <exception cref="System.Management.Automation.PSArgumentException">55 /// <paramref name="label"/> is null or empty.56 /// </exception>57 /// <exception cref="System.Management.Automation.PSArgumentNullException">58 /// <paramref name="helpMessage"/> is null.59 /// </exception>60 public61 ChoiceDescription(string label, string helpMessage)62 {63 // the only required parameter is label.64 65 if (string.IsNullOrEmpty(label))66 {67 // "label" is not localizable68 throw PSTraceSource.NewArgumentException(nameof(label), DescriptionsStrings.NullOrEmptyErrorTemplate, "label");69 }70 71 if (helpMessage == null)72 {73 // "helpMessage" is not localizable74 throw PSTraceSource.NewArgumentNullException(nameof(helpMessage));75 }76 77 this.label = label;78 this.helpMessage = helpMessage;79 }80 81 /// <summary>82 /// Gets a short, human-presentable message to describe and identify the choice. Think Button label.83 /// </summary>84 /// <remarks>85 /// Note that the special character & (ampersand) may be embedded in the label string to identify the next character in the label86 /// as a "hot key" (aka "keyboard accelerator") that the Console.PromptForChoice implementation may use to allow the user to87 /// quickly set input focus to this choice. The implementation of <see cref="System.Management.Automation.Host.PSHostUserInterface.PromptForChoice"/>88 /// is responsible for parsing the label string for this special character and rendering it accordingly.89 ///90 /// For examples, a choice named "Yes to All" might have "Yes to &All" as it's label.91 /// </remarks>92 public93 string94 Label95 {96 get97 {98 Dbg.Assert(this.label != null, "label should not be null");99 100 return this.label;101 }102 }103 104 /// <summary>105 /// Gets and sets the help message for this field.106 /// </summary>107 /// <exception cref="System.Management.Automation.PSArgumentNullException">108 /// Set to null.109 /// </exception>110 /// <remarks>111 /// This should be a few sentences to describe the field, suitable for presentation as a tool tip.112 /// Avoid placing including formatting characters such as newline and tab.113 /// </remarks>114 public115 string116 HelpMessage117 {118 get119 {120 Dbg.Assert(this.helpMessage != null, "helpMessage should not be null");121 122 return this.helpMessage;123 }124 125 set126 {127 if (value == null)128 {129 throw PSTraceSource.NewArgumentNullException("value");130 }131 132 this.helpMessage = value;133 }134 }135 }136}137 