Udostępnij za pośrednictwem


IArgumentCompleterFactory Interface

Definition

Creates a new argument completer.

public interface IArgumentCompleterFactory
type IArgumentCompleterFactory = interface
Public Interface IArgumentCompleterFactory
Derived

Examples

This example shows the intended usage of IArgumentCompleterFactory to pass arguments to an argument completer.

public class NumberCompleterAttribute : ArgumentCompleterAttribute, IArgumentCompleterFactory {
   private readonly int _from;
   private readonly int _to;

   public NumberCompleterAttribute(int from, int to){
      _from = from;
      _to = to;
   }

   // use the attribute parameters to create a parameterized completer
   IArgumentCompleter Create() => new NumberCompleter(_from, _to);
}

class NumberCompleter : IArgumentCompleter {
   private readonly int _from;
   private readonly int _to;

   public NumberCompleter(int from, int to){
      _from = from;
      _to = to;
   }

   IEnumerable{CompletionResult} CompleteArgument(string commandName, string parameterName, string wordToComplete,
      CommandAst commandAst, IDictionary fakeBoundParameters) {
      for(int i = _from; i < _to; i++) {
          yield return new CompletionResult(i.ToString());
      }
   }
}

Methods

Create()

Creates an instance of a class implementing the IArgumentCompleter interface.

Applies to