public static DistributableObject Create(ByteList bytes) { DistributableObject result = null; if (bytes == null || bytes.RemainingToRead < 4) { throw new ApplicationException("Invalid byte array"); } DISTRIBUTABLE_CLASS_IDS objType = (DISTRIBUTABLE_CLASS_IDS)bytes.PeekInt16(); switch (objType) { case DISTRIBUTABLE_CLASS_IDS.MessageNumber: result = MessageNumber.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.Bomb: result = Bomb.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.AgentInfo: result = AgentInfo.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.AgentList: result = AgentList.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.EndPoint: result = EndPoint.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.Excuse: result = Excuse.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.FieldLocation: result = FieldLocation.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.GameConfiguration: result = GameConfiguration.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.PlayingFieldLayout: result = PlayingFieldLayout.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.Tick: result = Tick.Create(bytes); break; case DISTRIBUTABLE_CLASS_IDS.WhiningTwine: result = WhiningTwine.Create(bytes); break; default: throw new ApplicationException(string.Format("Invalid Class Id={0}", objType)); } return(result); }