public SerializableObjectFactory(Assembly[] assemblies, bool forServer) { var types = ReflectionHelpers.GetTypesThatImplementInterfaces(assemblies, new Type[] { typeof(SerializableObject) }); foreach (var t in types) { var ctor = t.GetConstructor(System.Type.EmptyTypes); if (ctor != null) { var obj = ctor.Invoke(null) as SerializableObject; if ((forServer && (obj.serverType == t)) || (!forServer && (obj.clientType == t))) { if (objTypes.Contains(obj.classID)) { throw new System.Exception(t.FullName + " collides with an existing type!"); } else { objTypes.Add(obj.classID, ctor); } } } else { throw new TargetInvocationException(t.FullName + " does not have a constructor!", null); } } }
void AddRPCMethods(Type t, BindingFlags flags) { var typeMethods = t.GetMethods(flags); foreach (var minfo in typeMethods) { var rpcAttrs = minfo.GetCustomAttributes(typeof(RPC), false); if (rpcAttrs.Length == 1) { var actualMethod = minfo.GetBaseDefinition(); var sig = GenerateMethodSignature(actualMethod); if (!methods.ContainsKey(sig)) { int rpcID = methods.Count; methods.Add(sig, rpcID); var actorRPC = new ObjectRPCSerializer(rpcAttrs[0] as RPC, actualMethod); rpcIDToRPC.Add(rpcID, actorRPC); } } } }
public NetMsgFactory(Assembly[] assemblies, bool forServer) { var types = ReflectionHelpers.GetTypesThatImplementInterfaces(assemblies, new[] { typeof(NetMsg) }); foreach (var t in types) { var ctor = t.GetConstructor(System.Type.EmptyTypes); if (ctor != null) { var netMsg = ctor.Invoke(null) as NetMsg; if ((netMsg.isServerMsg && forServer) || (netMsg.isClientMsg && !forServer)) { if (netMsg.shareInstance != null) { netMsg = netMsg.shareInstance; } else { netMsg.Init(); } if (netMsgs.Contains(netMsg.msgTypeID)) { throw new System.Exception(t.FullName + " collides with an existing type!"); } else { netMsgs.Add(netMsg.msgTypeID, netMsg); } } else if (netMsg.shareInstance == null) { netMsg.Init(); // clients need to init server net messages to send. } } else { throw new TargetInvocationException(t.FullName + " does not have a constructor!", null); } } }
public void Add(int k, V v) { hashtable.Add(k, v); list.Add(v); }