private static void Register(BaseAttributeRegister register) { register.RegisterHandler(RegisterType.ClassAttr, typeof(NetAutoRegisterAttribute), RegisterToConnection); }
public void Analyze(BaseAttributeRegister register, int tp, TypeListWrapper wrapper, Type attname, BaseAttributeRegister.GameAttriHandler handler) { //if (!attname.FullName.Equals(wrapper.attributename)) // return; RegisterType registerType = (RegisterType)tp; if (registerType == RegisterType.ClassAttr) { Type clstype = Type.GetType(wrapper.name); if (clstype == null) { LogMgr.LogErrorFormat("cant find class:{0}", wrapper.name); } else { object[] atts = clstype.GetCustomAttributes(attname, true); if (atts.Length > 0) { handler(atts[0], clstype); } else { LogMgr.LogErrorFormat("missing attribute :{0} from {1}", clstype, attname); } } } else if (registerType == RegisterType.MethodAtt || registerType == RegisterType.Register) { if (wrapper.seekTargetList.Count == 0) { LogMgr.LogErrorFormat("没有匹配的函数 :{0} From :{1}", attname, wrapper.name); } else { Type clstype = Type.GetType(wrapper.name); if (clstype == null) { LogMgr.LogErrorFormat("cant find class:{0}", wrapper.name); } else { for (int i = 0; i < wrapper.seekTargetList.Count; ++i) { string target = wrapper.seekTargetList[i]; MethodInfo targetMethod = clstype.GetMethod(target, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (targetMethod == null) { LogMgr.LogErrorFormat("没有匹配的函数 :{0} From :{1} named :{2}", attname, wrapper.name, target); continue; } object[] atts = targetMethod.GetCustomAttributes(attname, true); if (atts.Length == 0) { LogMgr.LogErrorFormat("method {0} in {1} missing attribute:{2}", targetMethod.Name, wrapper.name, attname.Name); } else { if (registerType == RegisterType.Register) { handler(atts[0], new KeyValuePair <BaseAttributeRegister, MethodInfo> (register, targetMethod)); } else { handler(atts[0], targetMethod); } } } } } } else { LogMgr.LogError("error"); } }