/// <summary> /// crawls the given method (attributes still needed) and adds it to the speech dictionary /// </summary> /// <param name="methodInfo">the method to crawl</param> /// <param name="invokingInstance">the instance to invoke the speech methods or null to create one with the parameterless constructor ( /// static methods doesnt need a invoking instance so leave this null)</param> /// <param name="reloadGrammarIfNeeded">true: automatically reload the grammar, false: user need to call RebuildAllCommands</param> public void AddCommand(MethodInfo methodInfo, object invokingInstance = null, bool reloadGrammarIfNeeded = false) { var commands = new List <SpeechMethod>(); Crawler.CrawMethods(methodInfo.DeclaringType, commands, this.AllCommands.Converters, methodInfo); bool newGrammar = false; foreach (var speechMethod in commands) { this.AllCommands.AddMethod(speechMethod, invokingInstance); if (speechMethod.Lang == this._currentInputCulture) { foreach (var speechName in speechMethod.SpeechNames) { _currentCommandChoices.Add(speechName); newGrammar = true; } } } if (newGrammar && reloadGrammarIfNeeded) { ExtendCurrentGrammar(this._currentCommandChoices, ref this.CommandGrammar); } }