/// <summary> /// 快速构建Tcp服务端 /// </summary> public FastTcpClient() { this.apiActionList = new ApiActionList(FastTcpCommon.GetServiceApiActions(this.GetType())); this.packetIdProvider = new PacketIdProvider(); this.taskSetActionTable = new TaskSetActionTable(); this.Serializer = new DefaultSerializer(); }
/// <summary> /// 绑定服务 /// </summary> /// <param name="apiServiceType">Api服务类型</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <returns></returns> public FastTcpServer BindService(IEnumerable <Type> apiServiceType) { if (apiServiceType == null) { throw new ArgumentNullException("apiServiceType"); } if (apiServiceType.Count() == 0) { throw new ArgumentOutOfRangeException("apiServiceType", "apiServiceType集合不能为空"); } if (apiServiceType.Any(item => item == null)) { throw new ArgumentException("apiServiceType不能含null值"); } if (apiServiceType.Any(item => item.IsInterface || item.IsAbstract)) { throw new ArgumentException("apiServiceType不能是接口或抽象类"); } if (apiServiceType.Any(item => typeof(IFastApiService).IsAssignableFrom(item) == false)) { throw new ArgumentException("apiServiceType必须派生于IFastApiService"); } foreach (var type in apiServiceType) { var actions = FastTcpCommon.GetServiceApiActions(type); this.apiActionList.AddRange(actions); } return(this); }