Esempio n. 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()));
 }
Esempio n. 2
0
 public CommandAttributeLoader(ReflectionFinder finder)
 {
     types = finder.GetUserClassesAndStructs();
 }