public void Init() { m_methods.Clear(); System.Type type = typeof(GMModule); var methods = type.GetMethods(); foreach (var each in methods) { var attribute = each.GetCustomAttributes(typeof(GMCommondAttribute), false); if (attribute != null && attribute.Length > 0) { GMCommondAttribute gmc = attribute[0] as GMCommondAttribute; m_methods.Add(gmc.Cmd, each); } } }
public void Init() { this.methods.Clear(); Type type = typeof(GMModule); var methods = type.GetMethods(); foreach (var item in methods) { var attrs = item.GetCustomAttributes(typeof(GMCommondAttribute), false); if (attrs != null && attrs.Length > 0) { foreach (var attr in attrs) { if (attr is GMCommondAttribute) { GMCommondAttribute gmc = attr as GMCommondAttribute; this.methods.Add(gmc.cmd, item); } } } } }
public string Call(string input) { var tmpStr = input.Split(' '); if (methods.ContainsKey(tmpStr[0])) { List <string> param = new List <string>(); for (int i = 1; i < tmpStr.Length; i++) { param.Add(tmpStr[i]); } var method = methods[tmpStr[0]]; var infos = method.GetCustomAttributes(typeof(GMCommondAttribute), false); GMCommondAttribute info = null; foreach (var item in infos) { if (item is GMCommondAttribute) { info = item as GMCommondAttribute; } } if (param.Count != info.paramNum) { return("Usage:" + info.usage); } else { return(methods[tmpStr[0]].Invoke( this, new object[] { param.ToArray() }) as string); } } else { return("Common Not Fount!"); } }