本文整理汇总了C#中ICommand.Initialise方法的典型用法代码示例。如果您正苦于以下问题:C# ICommand.Initialise方法的具体用法?C# ICommand.Initialise怎么用?C# ICommand.Initialise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommand
的用法示例。
在下文中一共展示了ICommand.Initialise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
/// <summary>
/// Executes a command
/// </summary>
/// <param name="cmd">The command to execute</param>
/// <param name="args">Arguments to apply to the command</param>
/// <param name="directive">Directives to execute with</param>
/// <returns>The outcome of the execution</returns>
private CommandResult ExecuteCommand(ICommand cmd, string[] args, ExecutionDirective directive)
{
cmd.Initialise(_context, _formatter);
CommandResult result = null;
var manualParseInterface = CommandInspector.GetManualParseCommand(cmd);
if (manualParseInterface != null)
{
var subArgs = from arg in args
select Parser.PerformSubstitution(_context, arg);
result = manualParseInterface.Run(subArgs.ToArray());
}
else
{
var properties = cmd.GetType().GetProperties();
object propValue = null;
var processingArgs = args;
// Process multi-word named parameters first
foreach (var prop in properties)
{
propValue = null;
var namedParameterAttribute = CommandInspector.GetNamedParameter(prop);
if (namedParameterAttribute != null && namedParameterAttribute.WordCount > 1)
{
var words = new List<string>();
for (var i = 0; i < namedParameterAttribute.WordCount; i++)
{
var value = string.Empty;
ParameterUtil.GetParameter(args, "-" + namedParameterAttribute.Name, i, ref value);
if (!string.IsNullOrEmpty(value))
words.Add(value);
}
if (words.Count > 0)
{
propValue = words.ToArray();
processingArgs = ParameterUtil.RemoveParameter(processingArgs, "-" + namedParameterAttribute.Name, namedParameterAttribute.WordCount);
}
}
ConvertAndAssignParameter(prop, cmd, propValue);
}
// Find flags
var flags = from prop in properties
let attr = CommandInspector.GetFlagParameter(prop)
where attr != null
select attr.Name;
// Parse remaining arguments
StringDictionary named = null;
string[] numbered = null;
ParameterUtil.ExtractParameters(out named, out numbered, processingArgs, flags.ToArray());
// Map the parameters to properties
foreach (var prop in properties)
{
propValue = null;
var namedParameterAttribute = CommandInspector.GetNamedParameter(prop);
if (namedParameterAttribute != null)
{
if (named.ContainsKey(namedParameterAttribute.Name))
propValue = named[namedParameterAttribute.Name];
}
var numberedParameterAttribute = CommandInspector.GetNumberedParameter(prop);
if (numberedParameterAttribute != null)
{
if (numberedParameterAttribute.Number < numbered.Length)
propValue = numbered[numberedParameterAttribute.Number];
}
var flagParameterAttribute = CommandInspector.GetFlagParameter(prop);
if (flagParameterAttribute != null)
{
if (named.ContainsKey(flagParameterAttribute.Name))
{
#if NET45
var origVal = (bool)prop.GetValue(cmd);
#else
var origVal = (bool)prop.GetValue(cmd, null);
#endif
propValue = !origVal;
}
}
ConvertAndAssignParameter(prop, cmd, propValue);
//.........这里部分代码省略.........
示例2: InitCommand
protected virtual void InitCommand(ICommand command)
{
_command = command;
_context.CurrentDatabase = _database;
_command.Initialise(_context, new TextOutputFormatter());
}