//----------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. // // // Implements CompletionResult. // //----------------------------------------------------------------------- namespace System.Management.Automation { using System; /// /// Possible types of CompletionResults /// public enum CompletionResultType { /// An unknown result type, kept as text only Text = 0, /// A history result type like the items out of get-history History = 1, /// A command result type like the items out of get-command Command = 2, /// A provider item ProviderItem = 3, /// A provider container ProviderContainer = 4, /// A property result type like the property items out of get-member Property = 5, /// A method result type like the method items out of get-member Method = 6, /// A parameter name result type like the Parameters property out of get-command items ParameterName = 7, /// A parameter value result type ParameterValue = 8, /// A variable result type like the items out of get-childitem variable: Variable = 9, /// A namespace Namespace = 10, /// A type name Type = 11, /// A keyword Keyword = 12, /// A dynamic keyword DynamicKeyword = 13, // If a new enum is added, there is a range test that uses DynamicKeyword for parameter validation // that needs to be updated to use the new enum. // We can't use a "MaxValue" enum because it's value would preclude ever adding a new enum. } /// /// Class used to store a tab completion or Intellisense result /// public class CompletionResult { /// /// Text to be used as the auto completion result /// private string _completionText; /// /// Text to be displayed in a list /// private string _listItemText; /// /// The text for the tooltip with details to be displayed about the object /// private string _toolTip; /// /// Type of completion result /// private CompletionResultType _resultType; /// /// Private member for null instance /// private static readonly CompletionResult s_nullInstance = new CompletionResult(); /// /// Gets the text to be used as the auto completion result /// public string CompletionText { get { if (this == s_nullInstance) { throw PSTraceSource.NewInvalidOperationException(TabCompletionStrings.NoAccessToProperties); } return _completionText; } } /// /// Gets the text to be displayed in a list /// public string ListItemText { get { if (this == s_nullInstance) { throw PSTraceSource.NewInvalidOperationException(TabCompletionStrings.NoAccessToProperties); } return _listItemText; } } /// /// Gets the type of completion result /// public CompletionResultType ResultType { get { if (this == s_nullInstance) { throw PSTraceSource.NewInvalidOperationException(TabCompletionStrings.NoAccessToProperties); } return _resultType; } } /// /// Gets the text for the tooltip with details to be displayed about the object /// public string ToolTip { get { if (this == s_nullInstance) { throw PSTraceSource.NewInvalidOperationException(TabCompletionStrings.NoAccessToProperties); } return _toolTip; } } /// /// Gets the null instance of type CompletionResult /// internal static CompletionResult Null { get { return s_nullInstance; } } /// /// Initializes a new instance of the CompletionResult class /// /// the text to be used as the auto completion result /// he text to be displayed in a list /// the type of completion result /// the text for the tooltip with details to be displayed about the object public CompletionResult(string completionText, string listItemText, CompletionResultType resultType, string toolTip) { if (String.IsNullOrEmpty(completionText)) { throw PSTraceSource.NewArgumentNullException("completionText"); } if (String.IsNullOrEmpty(listItemText)) { throw PSTraceSource.NewArgumentNullException("listItemText"); } if (resultType < CompletionResultType.Text || resultType > CompletionResultType.DynamicKeyword) { throw PSTraceSource.NewArgumentOutOfRangeException("resultType", resultType); } if (String.IsNullOrEmpty(toolTip)) { throw PSTraceSource.NewArgumentNullException("toolTip"); } _completionText = completionText; _listItemText = listItemText; _toolTip = toolTip; _resultType = resultType; } /// /// Initializes a new instance of this class internally if the result out of TabExpansion is a string /// /// completion text public CompletionResult(string completionText) : this(completionText, completionText, CompletionResultType.Text, completionText) { } /// /// An null instance of CompletionResult. /// /// /// /// This can be used in argument completion, to indicate that the completion attempt has gone through the /// native command argument completion methods. /// private CompletionResult() { } } }