public static void BuildRPCMethordExecuter(System.Reflection.Assembly assembly) { System.Type[] ctypes = assembly.GetTypes(); foreach (System.Type t in ctypes) { if (t.FullName == "RPC_ExecuterNamespace.MappingHashCode2Index") { System.Reflection.MethodInfo buildMI = t.GetMethod("BuildMapping"); if (buildMI != null) { buildMI.Invoke(System.Activator.CreateInstance(t), new System.Object[0]); } } { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCMethordExecuterTypeAttribute), true); if (attrs != null && attrs.Length == 1) { RPCMethordExecuterTypeAttribute att = (RPCMethordExecuterTypeAttribute)(attrs[0]); if (att == null) { continue; } RPCNetworkMgr.AddExecuterType(att.KeyCode, att.ExecuterType); } } { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCIndexExecuterTypeAttribute), true); if (attrs != null && attrs.Length == 1) { RPCIndexExecuterTypeAttribute att = (RPCIndexExecuterTypeAttribute)(attrs[0]); if (att == null) { continue; } RPCNetworkMgr.AddIndexExecuterType(att.KeyCode, att.ExecuterType); } } } foreach (System.Type t in ctypes) { System.Object[] attrs = t.GetCustomAttributes(typeof(RPCClassAttribute), false); if (attrs != null && attrs.Length == 1) { RPCClassAttribute att = (RPCClassAttribute)(attrs[0]); if (att == null) { continue; } System.Reflection.MethodInfo mtd_GetRPCClassInfo = t.GetMethod("GetRPCClassInfo"); if (mtd_GetRPCClassInfo == null) { continue; } System.Object obj = System.Activator.CreateInstance(t); RPCClassInfo cInfos = (RPCClassInfo)mtd_GetRPCClassInfo.Invoke(obj, null); if (cInfos == null) { continue; } BuildRPCClassInfo(t, cInfos); } } }
public static void BuildRPCClassInfo(System.Type type, RPCClassInfo cInfos) { cInfos.ObjType = type; System.Reflection.PropertyInfo[] props = type.GetProperties(); foreach (System.Reflection.PropertyInfo p in props) { if (p.Name == "Item") { System.Object[] attrs = p.GetCustomAttributes(typeof(RPCIndexObjectAttribute), true); if (attrs == null || attrs.Length == 0) { continue; } RPCIndexObjectAttribute att = (RPCIndexObjectAttribute)(attrs[0]); if (att == null) { continue; } System.Type exeType = RPCNetworkMgr.FindIndexExecuterType(GetIndexerHashCode(p, type.FullName)); if (exeType == null) { continue; } RPCIndexerExecuter executer = (RPCIndexerExecuter)System.Activator.CreateInstance(exeType); executer.mMethodName = type.FullName + "." + p.ToString(); cInfos.mIndexers[att.ChildIndex] = executer; continue; } else { System.Object[] attrs = p.GetCustomAttributes(typeof(RPCChildObjectAttribute), true); if (attrs != null && attrs.Length == 1) { RPCChildObjectAttribute att = (RPCChildObjectAttribute)(attrs[0]); if (att == null) { continue; } cInfos.mChildObjects[att.ChildIndex] = p; } } } System.Reflection.MethodInfo[] methords = type.GetMethods(); foreach (System.Reflection.MethodInfo m in methords) { System.Object[] attrs = m.GetCustomAttributes(typeof(RPCMethodAttribute), true); if (attrs != null && attrs.Length == 1) { RPCMethodAttribute att = (RPCMethodAttribute)(attrs[0]); if (att == null) { continue; } System.UInt32 hashCode = GetMethodHashCode(m, type.FullName); System.Type exeType = RPCNetworkMgr.FindExecuterType(hashCode); if (exeType == null) { continue; } System.Byte methodIndexer = RPCNetworkMgr.FindExecuterIndexer(hashCode); RPCMethodExecuter executer = (RPCMethodExecuter)System.Activator.CreateInstance(exeType); executer.mMethodFullName = type.FullName + "." + m.ToString(); executer.mMethodName = m.Name; cInfos.mMethods[methodIndexer] = executer; } } RpcAllClassInfo.Add(cInfos); }