internal static void AddReceiversWithInstance(object instance) { Type tp = instance.GetType(); List <ReceiverMeta> receiveList = null; if (!mReceiverMetas.TryGetValue(tp, out receiveList)) { receiveList = new List <ReceiverMeta>(); mReceiverMetas.Add(tp, receiveList); MethodInfo[] methods = tp.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (methods != null && methods.Length > 0) { foreach (var method in methods) { object[] objs = method.GetCustomAttributes(typeof(Receiver), true); if (objs != null && objs.Length > 0) { ReceiverMeta meta = new ReceiverMeta(); meta.method = method; meta.attributes = objs; receiveList.Add(meta); } } } } if (receiveList.Count > 0) { for (int i = 0; i < receiveList.Count; ++i) { var meta = receiveList[i]; foreach (var obj in meta.attributes) { Receiver attr = (Receiver)obj; ReceiverData receiver = new ReceiverData(); receiver.call.instance = instance; receiver.call.method = meta.method; receiver.type = attr.dataType; DataCenter.AddReceiver(receiver); } } } }
internal static void AddReceiversStatic(Type tp) { MethodInfo[] methods = tp.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (methods != null && methods.Length > 0) { foreach (var method in methods) { //var objs = method.GetCustomAttributesData(); //foreach (var obj in objs) //{ // //Receiver attr = (Receiver)obj; // //ReceiverData receiver = new ReceiverData(); // //receiver.call.instance = null; // //receiver.call.method = method; // //receiver.type = attr.dataType; // //DataCenter.AddReceiver(receiver); //} object[] objs = method.GetCustomAttributes(typeof(Receiver), false); if (objs != null && objs.Length > 0) { foreach (var obj in objs) { Receiver attr = (Receiver)obj; ReceiverData receiver = new ReceiverData(); receiver.call.instance = null; receiver.call.method = method; receiver.type = attr.dataType; DataCenter.AddReceiver(receiver); } } } } }