当前位置: 首页>>代码示例>>C#>>正文


C# Command.GetType方法代码示例

本文整理汇总了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);
 }
开发者ID:vgrinin,项目名称:gin,代码行数:8,代码来源:ExternalCommand.cs

示例2: CommandContext

        public CommandContext(Command command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            Command = command;
            Assembly = command.GetType().Assembly;
        }
开发者ID:Boggin,项目名称:Consolas,代码行数:8,代码来源:CommandContext.cs

示例3: Process

 public void Process(Command command)
 {
     try
     {
         ActualCommandProcessing(command);
     }
     catch
     {
         errorMeter.Mark(command.GetType().Name);
     }
 }
开发者ID:dynamicdeploy,项目名称:Metrics.NET,代码行数:11,代码来源:SetMeterSample.cs

示例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});
        }
开发者ID:titarenko,项目名称:Cqrsnes,代码行数:24,代码来源:SimpleBus.cs

示例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);
     }
 }
开发者ID:gidish,项目名称:PlanckDB,代码行数:22,代码来源:KeyValueAdapter.cs

示例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
                         });
                     }
                 }
             }
         }
     }
 }
开发者ID:vgrinin,项目名称:gin,代码行数:50,代码来源:ResultInfoVisitor.cs

示例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);
                }
            }
        }
开发者ID:BlueSky007,项目名称:DemoDealingConsole,代码行数:20,代码来源:Service2.asmx.cs

示例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 + ") отсутствует параметр 'Имя результата'"
                 });
             }
         }
     }
 }
开发者ID:vgrinin,项目名称:gin,代码行数:21,代码来源:CheckPackageVisitor.cs

示例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;
                }

//.........这里部分代码省略.........
开发者ID:emul8,项目名称:emul8,代码行数:101,代码来源:MonitorCommands.cs

示例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();

	}
开发者ID:GNOME,项目名称:gnome-subtitles,代码行数:31,代码来源:CommandManager.cs

示例11: CommandScriptStepAudit

 public CommandScriptStepAudit(Command command, CommandScriptStepResult result)
 {
     _result = result;
     _type = command.GetType();
 }
开发者ID:CharlieBP,项目名称:Topshelf,代码行数:5,代码来源:CommandScriptStepAudit.cs

示例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());
 }
开发者ID:gidish,项目名称:PlanckDB,代码行数:22,代码来源:KeyValueAdapter.cs

示例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;
        }
开发者ID:AlbinoDrought,项目名称:SharpClap,代码行数:63,代码来源:DialogHelper.cs

示例14: Send

 public void Send(Command cmd)
 {
     _commandHandlers[cmd.GetType()].Handle(cmd);
 }
开发者ID:alreva,项目名称:CQRS_Example,代码行数:4,代码来源:CommandSender.cs

示例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();
        }
开发者ID:groma84,项目名称:IwAutoUpdater,代码行数:26,代码来源:SendErrorNotifications.cs


注:本文中的Command.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。