public void AddCommand(string id, ConsoleCommandHandler handler) { ConsoleCommand newCommand = new ConsoleCommand(id, handler); //newCommand.SetFlag( (int)flags ); if (_commandTable[""].ContainsKey(id)) _commandTable[""][id] = newCommand; else _commandTable[""].Add(id, newCommand); }
public void LoadMembersFromAssembly(Assembly assm) { #if WINDOWS // Don't bother with GAC entries if (assm.GlobalAssemblyCache == true) return; #endif foreach (Type type in assm.GetTypes()) { string sshortTypeName = type.Name; string stypeName = type.FullName; if (type.IsGenericType || type.IsGenericTypeDefinition || type.IsInterface || type.BaseType.IsGenericType) continue; MemberInfo[] info = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static); for (int i = 0; i < info.Length; ++i) { if (info[i].MemberType == MemberTypes.Method) { ConsoleMethodAttribute[] method = (ConsoleMethodAttribute[])info[i].GetCustomAttributes(typeof(ConsoleMethodAttribute), true); if (method != null && method.Length > 0) { string name = method[0].Name; if (name == null) name = info[i].Name; ConsoleCommand newCommand = new ConsoleCommand(name, (MethodInfo)info[i]); newCommand.SetFlag((int)method[0].Flags); MethodInfo myinfo = (MethodInfo)info[i]; string tableKey = stypeName; if (myinfo.IsStatic) tableKey = sshortTypeName; if (!_commandTable.ContainsKey(tableKey)) _commandTable.Add(tableKey, new Dictionary<string, ConsoleCommand>()); if (_commandTable[tableKey].ContainsKey(name)) _commandTable[tableKey][name] = newCommand; else _commandTable[tableKey].Add(name, newCommand); } } else if (info[i].MemberType == MemberTypes.Property) { ConsolePropertyAttribute[] method = (ConsolePropertyAttribute[])info[i].GetCustomAttributes(typeof(ConsolePropertyAttribute), true); if (method != null && method.Length > 0) { string name = method[0].Name; if (name == null) name = info[i].Name; PropertyInfo myinfo = (PropertyInfo)info[i]; if (!_objPropertyTable.ContainsKey(stypeName)) _objPropertyTable.Add(stypeName, new Dictionary<string, PropertyInfo>()); if (_objPropertyTable.ContainsKey(name)) _objPropertyTable[stypeName][name] = myinfo; else _objPropertyTable[stypeName].Add(name, myinfo); } } } } }