"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/src/System.Management.Automation/help/AliasHelpInfo.cs" (11 Aug 2022, 3816 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AliasHelpInfo.cs" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) Microsoft Corporation.
    2 // Licensed under the MIT License.
    3 
    4 using System.Diagnostics.CodeAnalysis; // for fxcop
    5 
    6 namespace System.Management.Automation
    7 {
    8     /// <summary>
    9     /// Stores help information related to Alias Commands.
   10     /// </summary>
   11     internal sealed class AliasHelpInfo : HelpInfo
   12     {
   13         /// <summary>
   14         /// Initializes a new instance of the AliasHelpInfo class.
   15         /// </summary>
   16         /// <remarks>
   17         /// The constructor is private. The only way to create an
   18         /// AliasHelpInfo object is through static method <see cref="GetHelpInfo"/>
   19         /// </remarks>
   20         [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
   21         private AliasHelpInfo(AliasInfo aliasInfo)
   22         {
   23             _fullHelpObject = new PSObject();
   24 
   25             string name = (aliasInfo.ResolvedCommand == null) ? aliasInfo.UnresolvedCommandName : aliasInfo.ResolvedCommand.Name;
   26 
   27             this.ForwardTarget = name;
   28             // A Cmdlet/Function/Script etc can have alias.
   29             this.ForwardHelpCategory = HelpCategory.Cmdlet |
   30                 HelpCategory.Function | HelpCategory.ExternalScript | HelpCategory.ScriptCommand | HelpCategory.Filter;
   31 
   32             if (!string.IsNullOrEmpty(aliasInfo.Name))
   33             {
   34                 Name = aliasInfo.Name.Trim();
   35             }
   36 
   37             if (!string.IsNullOrEmpty(name))
   38             {
   39                 Synopsis = name.Trim();
   40             }
   41 
   42             _fullHelpObject.TypeNames.Clear();
   43             _fullHelpObject.TypeNames.Add(string.Format(Globalization.CultureInfo.InvariantCulture,
   44                 "AliasHelpInfo#{0}", Name));
   45             _fullHelpObject.TypeNames.Add("AliasHelpInfo");
   46             _fullHelpObject.TypeNames.Add("HelpInfo");
   47         }
   48 
   49         /// <summary>
   50         /// Returns the name of alias help.
   51         /// </summary>
   52         /// <value>Name of alias help.</value>
   53         internal override string Name { get; } = string.Empty;
   54 
   55         /// <summary>
   56         /// Returns synopsis of alias help.
   57         /// </summary>
   58         /// <value>Synopsis of alias help.</value>
   59         internal override string Synopsis { get; } = string.Empty;
   60 
   61         /// <summary>
   62         /// Help category for alias help. This is always HelpCategory.Alias.
   63         /// </summary>
   64         /// <value>Help category for alias help</value>
   65         internal override HelpCategory HelpCategory
   66         {
   67             get
   68             {
   69                 return HelpCategory.Alias;
   70             }
   71         }
   72 
   73         private readonly PSObject _fullHelpObject;
   74 
   75         /// <summary>
   76         /// Returns full help object for alias help.
   77         /// </summary>
   78         /// <value>Full help object of alias help.</value>
   79         internal override PSObject FullHelp
   80         {
   81             get
   82             {
   83                 return _fullHelpObject;
   84             }
   85         }
   86 
   87         /// <summary>
   88         /// Creates an AliasHelpInfo instance based on an AliasInfo object.
   89         /// This is the only way to create AliasHelpInfo object from outside this class.
   90         /// </summary>
   91         /// <param name="aliasInfo">AliasInfo object for which to create AliasHelpInfo object.</param>
   92         /// <returns>AliasHelpInfo object.</returns>
   93         internal static AliasHelpInfo GetHelpInfo(AliasInfo aliasInfo)
   94         {
   95             if (aliasInfo == null)
   96                 return null;
   97 
   98             if (aliasInfo.ResolvedCommand == null && aliasInfo.UnresolvedCommandName == null)
   99                 return null;
  100 
  101             AliasHelpInfo aliasHelpInfo = new AliasHelpInfo(aliasInfo);
  102 
  103             if (string.IsNullOrEmpty(aliasHelpInfo.Name))
  104                 return null;
  105 
  106             aliasHelpInfo.AddCommonHelpProperties();
  107 
  108             return aliasHelpInfo;
  109         }
  110     }
  111 }