本文整理汇总了C#中Command.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Command.GetType方法的具体用法?C# Command.GetType怎么用?C# Command.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExternalCommand
public ExternalCommand(Command command)
{
CommandType = command.GetType();
Constructor = CommandType.GetConstructor(new Type[0]);
Instance = command;
Properties = CommandType.GetProperties();
Metadata = GetCommandMetadata(CommandType);
}
示例2: CommandContext
public CommandContext(Command command)
{
if (command == null)
throw new ArgumentNullException("command");
Command = command;
Assembly = command.GetType().Assembly;
}
示例3: Process
public void Process(Command command)
{
try
{
ActualCommandProcessing(command);
}
catch
{
errorMeter.Mark(command.GetType().Name);
}
}
示例4: Send
/// <summary>
/// Sends command to exactly one receiver (handler).
/// </summary>
/// <param name="command">Command to send.</param>
public void Send(Command command)
{
var type = typeof(ICommandHandler<>).MakeGenericType(command.GetType());
var handler = resolver.Resolve(type);
if (handler == null)
{
throw new InvalidOperationException("Can't find handler for given command.");
}
var method = handler.GetType()
.GetMethod("Handle", new[] {command.GetType()});
if (method == null)
{
throw new ApplicationException(
"ICommandHandler doesn't contain Handle method. Make sure it was not renamed.");
}
method.Invoke(handler, new object[] {command});
}
示例5: consume
public override void consume(Command command)
{
if(command.GetType().Equals(typeof(NewItemCommand))){
handleNewItemCommand((NewItemCommand) command);
}
if (command.GetType().Equals(typeof(RemoveItemCommand)))
{
handleRemoveItemCommand((RemoveItemCommand) command);
}
if (command.GetType().Equals(typeof(AddItemToCollectionCommand)))
{
handleAddItemToCollectionCommand((AddItemToCollectionCommand) command);
}
if (command.GetType().Equals(typeof(RemoveItemFromCollectionCommand)))
{
handleRemoveItemFromCollection((RemoveItemFromCollectionCommand) command);
}
if (command.GetType().Equals(typeof(UpdateItemCommand)))
{
handleUpdateItemCommand((UpdateItemCommand) command);
}
}
示例6: Visit
public override void Visit(Command command)
{
PropertyInfo[] properties = command.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
GinResultAttribute attr = (GinResultAttribute)property.GetCustomAttributes(typeof(GinResultAttribute), true).FirstOrDefault();
if (attr != null)
{
if (attr.Result != null)
{
string name = (string)property.GetValue(command, null);
if (!String.IsNullOrEmpty(name))
{
_list.Add(new ResultInfo()
{
Type = attr.Result,
Name = name,
Description = attr.Description
});
}
}
else if (_findRecursive && attr.Kind == CommandResultKind.Dynamic)
{
string name = (string)property.GetValue(command, null);
if (name == null)
{
continue;
}
ResultInfo find = _firstRunResults.FirstOrDefault(r => ExecutionContext.GetPercentedKey(r.Name) == name);
if (find == null)
{
continue;
}
List<ParsedResult> members = CMParseResult.GetObjectValueMembers(find.Type, null, name);
foreach (var member in members)
{
if (!String.IsNullOrEmpty(member.Name))
{
_list.Add(new ResultInfo()
{
Type = member.Type,
Name = member.Name,
Description = member.Description
});
}
}
}
}
}
}
示例7: AddCommand
public void AddCommand(Token token, Command command)
{
this.Context.Application.Lock();
Commands commands = (Commands)this.Context.Application["Commands"];
this.Context.Application.UnLock();
//Do AddCommand
commands.Add(token, command);
//Log
string isDebug = System.Configuration.ConfigurationSettings.AppSettings["IsDebug"];
if (isDebug != null && Convert.ToBoolean(isDebug))
{
string logCommands = System.Configuration.ConfigurationSettings.AppSettings["LogCommands"];
if (logCommands != null && (logCommands == "*" || logCommands.IndexOf(command.GetType().Name) > -1))
{
iExchange.Common.AppDebug.LogEvent("DealingConsole.Service2.AddCommand", token.ToString() + "\n" + command.ToString(), System.Diagnostics.EventLogEntryType.Warning);
}
}
}
示例8: CheckResultNamePresent
private void CheckResultNamePresent(Command command)
{
PropertyInfo[] properties = command.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
GinResultAttribute attr = (GinResultAttribute)property.GetCustomAttributes(typeof(GinResultAttribute), true).FirstOrDefault();
if (attr != null)
{
string name = (string)property.GetValue(command, null);
if (String.IsNullOrEmpty(name))
{
_errors.Add(new PackageErrorInfo
{
Body = _body,
Command = command,
Description = "У команды " + command + "(" + command.Description + ") отсутствует параметр 'Имя результата'"
});
}
}
}
}
示例9: RunCommand
private void RunCommand(ICommandInteraction writer, Command command, IList<Token> parameters)
{
var commandType = command.GetType();
var runnables = commandType.GetMethods().Where(x => x.GetCustomAttributes(typeof(RunnableAttribute), true).Any());
ICommandInteraction candidateWriter = null;
MethodInfo foundCandidate = null;
bool lastIsAccurateMatch = false;
IEnumerable<object> preparedParameters = null;
foreach(var candidate in runnables)
{
bool isAccurateMatch = false;
var candidateParameters = candidate.GetParameters();
var writers = candidateParameters.Where(x => typeof(ICommandInteraction).IsAssignableFrom(x.ParameterType)).ToList();
var lastIsArray = candidateParameters.Length > 0
&& typeof(IEnumerable<Token>).IsAssignableFrom(candidateParameters[candidateParameters.Length - 1].ParameterType);
if(writers.Count > 1
//all but last (and optional writer) should be tokens
|| candidateParameters.Skip(writers.Count).Take(candidateParameters.Length - writers.Count - 1).Any(x => !typeof(Token).IsAssignableFrom(x.ParameterType))
//last one should be Token or IEnumerable<Token>
|| (candidateParameters.Length > writers.Count
&& !typeof(Token).IsAssignableFrom(candidateParameters[candidateParameters.Length - 1].ParameterType)
&& !lastIsArray))
{
throw new RecoverableException(String.Format("Method {0} of command {1} has invalid signature, will not process further. You should file a bug report.",
candidate.Name, command.Name));
}
IList<Token> parametersWithoutLastArray = null;
IList<ParameterInfo> candidateParametersWithoutArrayAndWriters = null;
if(lastIsArray)
{
candidateParametersWithoutArrayAndWriters = candidateParameters.Skip(writers.Count).Take(candidateParameters.Length - writers.Count - 1).ToList();
if(parameters.Count < candidateParameters.Length - writers.Count) //without writer
{
continue;
}
parametersWithoutLastArray = parameters.Take(candidateParametersWithoutArrayAndWriters.Count()).ToList();
}
else
{
candidateParametersWithoutArrayAndWriters = candidateParameters.Skip(writers.Count).ToList();
if(parameters.Count != candidateParameters.Length - writers.Count) //without writer
{
continue;
}
parametersWithoutLastArray = parameters;
}
//Check for types
if(parametersWithoutLastArray.Zip(
candidateParametersWithoutArrayAndWriters,
(x, y) => new {FromUser = x.GetType(), FromMethod = y.ParameterType})
.Any(x => !x.FromMethod.IsAssignableFrom(x.FromUser)))
{
continue;
}
bool constraintsOk = true;
//Check for constraints
for(var i = 0; i < parametersWithoutLastArray.Count; ++i)
{
var attribute = candidateParametersWithoutArrayAndWriters[i].GetCustomAttributes(typeof(ValuesAttribute), true);
if(attribute.Any())
{
if(!((ValuesAttribute)attribute[0]).Values.Contains(parametersWithoutLastArray[i].GetObjectValue()))
{
constraintsOk = false;
break;
}
}
}
if(lastIsArray)
{
var arrayParameters = parameters.Skip(parametersWithoutLastArray.Count()).ToArray();
var elementType = candidateParameters.Last().ParameterType.GetElementType();
if(!arrayParameters.All(x => elementType.IsAssignableFrom(x.GetType())))
{
constraintsOk = false;
}
else
{
var array = Array.CreateInstance(elementType, arrayParameters.Length);
for(var i = 0; i < arrayParameters.Length; ++i)
{
array.SetValue(arrayParameters[i], i);
}
preparedParameters = parametersWithoutLastArray.Concat(new object[] { array });
}
}
else
{
preparedParameters = parameters;
}
if(!constraintsOk)
{
continue;
}
//.........这里部分代码省略.........
示例10: ProcessExecute
/* Private methods */
private void ProcessExecute (Command command) {
bool couldUndoBefore = CanUndo;
bool couldRedoBefore = CanRedo;
ClearRedo();
bool canGroup = false;
if (CanUndo && command.CanGroup) {
Command lastCommand = GetPreviousCommand();
if ((!lastCommand.StopsGrouping) && (lastCommand.GetType() == command.GetType()) && (command.CanGroupWith(lastCommand))) {
canGroup = true;
Command merged = command.MergeWith(lastCommand);
SetPreviousCommand(merged);
}
}
if (!canGroup) {
SetNextCommand(command);
Next();
undoCount = IncrementCount(undoCount);
}
if (!couldUndoBefore)
EmitUndoToggled();
if (couldRedoBefore)
EmitRedoToggled();
}
示例11: CommandScriptStepAudit
public CommandScriptStepAudit(Command command, CommandScriptStepResult result)
{
_result = result;
_type = command.GetType();
}
示例12: produce
public void produce(Command command)
{
if(command.GetType().IsSubclassOf(typeof(ModelCommand))){
lock(command){
getCore().consume(command);
if( ! command.isSucceed()){
throw new Exception(command.getCommandSatus().getMessage());
}
try {
Monitor.Wait(command, 12000000);
} catch (Exception e) {
throw new Exception("fail to execute command : "+command.ToString(),e);
}
}
}else{
getCore().consume(command);
}
if( ! command.isSucceed()){
throw new Exception(command.getCommandSatus().getMessage());
}
log.Info("releasing thread command version "+command.getVersion());
}
示例13: Edit
public static Command Edit(this GenericInputDialog gid, Command c)
{
Type commandType = c.GetType();
/*if (commandType == typeof(Delay))
{
Delay d = (Delay)c;
gid.Initialize(d);
if (gid.ShowDialog() == DialogResult.OK)
{
d.Value = (double)gid.Results["base"];
d.ValueModifier = (double)gid.Results["dev"];
}
}
else if (commandType == typeof(PressKey))
{
PressKey pk = (PressKey)c;
gid.Initialize(pk);
if (gid.ShowDialog() == DialogResult.OK)
{
string[] splitString = ((string)gid.Results["key"]).Split(',');
List<Extern.VirtualKeyShort> keyShorts = new List<Extern.VirtualKeyShort>();
List<Extern.ScanCodeShort> scanShorts = new List<Extern.ScanCodeShort>();
foreach (string key in splitString)
{
Extern.VirtualKeyShort vks;
Enum.TryParse((string)gid.Results["key"], true, out vks);
if (vks != Extern.VirtualKeyShort.NONE)
{
keyShorts.Add(vks);
scanShorts.Add(pk.GuessScanCode(vks));
}
}
pk.keyShort = keyShorts.ToArray();
pk.scanShort = scanShorts.ToArray();
}
}*/
// TODO:
// extension methods cannot be dynamically dispatched
// not working as I had hoped
// (have command of type Delay, uses extension with Delay parameter instead of command)
// Reflection?
if(commandType == typeof(Delay))
{
c = gid.Edit((Delay)c);
}
else if(commandType == typeof(PressKey))
{
c = gid.Edit((PressKey)c);
}
else
{
MessageBox.Show("Unable to edit type " + commandType.ToString());
}
return c;
}
示例14: Send
public void Send(Command cmd)
{
_commandHandlers[cmd.GetType()].Handle(cmd);
}
示例15: BuildBody
private string BuildBody(Command failedCommand, IEnumerable<CommandResult> resultsOfPreviousCommands)
{
var sb = new StringBuilder();
sb.AppendLine($"IWAutoUpdater: Command {failedCommand.GetType().Name} for Package {failedCommand.PackageName} failed with error: ");
foreach (var result in resultsOfPreviousCommands)
{
foreach (var error in result.Errors)
{
sb.AppendLine(error.Exception + " -- " + error.Text);
}
}
var blackboardEntries = _blackboard.Get(failedCommand.PackageName);
if (blackboardEntries.Count() > 0)
{
sb.AppendLine();
sb.AppendLine("Blackboard entries: ");
foreach (var blackboardEntry in blackboardEntries)
{
sb.AppendLine(blackboardEntry.Content.ToString());
}
}
return sb.ToString();
}