Пример #1
0
 //Finds every Parser method and adds it to the array
 void Load()
 {
     parsers = new Dictionary <Type, MethodInfo>();
     Type[] allTypes = finder.GetUserClassesAndStructs();
     for (int i = 0; i < allTypes.Length; i++)
     {
         MethodInfo[] methods = allTypes[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
         for (int j = 0; j < methods.Length; j++)
         {
             object[] attributes = methods[j].GetCustomAttributes(typeof(ParserAttribute), false);
             if (attributes.Length > 0)
             {
                 ParserAttribute parser = (ParserAttribute)attributes[0];
                 if (!parsers.ContainsKey(parser.type))
                 {
                     parsers.Add(parser.type, methods[j]);
                 }
                 else
                 {
                     CommandsManager.SendException(new DuplicatedParserException(parser));
                 }
             }
         }
     }
     dataLoaded = true;
     CommandsManager.SendMessage("Loaded " + parsers.Count + " parsers:\n" + string.Join("\n", parsers.ToList().ConvertAll(x => x.Key.Namespace + "." + SignatureBuilder.TypeToString(x.Key)).ToArray()));
 }
Пример #2
0
 void AddParser(ParserAttribute attribute, MethodInfo method)
 {
     if (!parsers.ContainsKey(attribute.type))
     {
         parsers.Add(attribute.type, method);
     }
     else
     {
         notificationsHandler.NotifyException(new DuplicatedParser(attribute));
     }
 }
Пример #3
0
 public DuplicatedParserException(ParserAttribute parser)
 {
     this.parser = parser;
 }