コード例 #1
0
ファイル: ResponseBase.cs プロジェクト: NoiTheCat/RegexBot
        public static ResponseBase[] ReadConfiguration(ConfigItem r, IEnumerable <string> responses)
        {
            var result = new List <ResponseBase>();

            foreach (var line in responses)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    throw new RuleImportException("Empty response line");
                }
                int    i = line.IndexOf(' ');
                string basecmd;
                if (i != -1)
                {
                    basecmd = line.Substring(0, i);
                }
                else
                {
                    basecmd = line;
                }

                Type rt;
                if (!_commands.TryGetValue(basecmd, out rt))
                {
                    throw new RuleImportException($"'{basecmd}' is not a valid response");
                }

                var newresponse = Activator.CreateInstance(rt, r, line) as ResponseBase;
                if (newresponse == null)
                {
                    throw new Exception("An unknown error occurred when attempting to create a new Response object.");
                }
                result.Add(newresponse);
            }
            return(result.ToArray());
        }
コード例 #2
0
ファイル: ResponseBase.cs プロジェクト: NoiTheCat/RegexBot
 /// <summary>
 /// Deriving constructor should do validation of incoming <paramref name="cmdline"/>.
 /// </summary>
 public ResponseBase(ConfigItem rule, string cmdline)
 {
     _rule    = rule;
     _cmdline = cmdline;
 }