私は自分のプロジェクトをセットアップするのに苦労しています。ジェネリックスとベースクラス
public WebSocketResponse HandleRequest(RequestDto request, GameSessionServer server)
{
TrySetThreadCulture(request);
EnsureUserStoredInSession(server.SessionContext, false, SlotIsEngineRNG(server.SessionContext.SystemGameId));
// custom request handling
WebSocketResponse wsr = HandleRequestInternal(request, server);
// save the last handler
server.SessionContext.Items[typeof(WebSocketHandler)] = this;
return wsr;
}
はそれがRequestDto基本クラスのパラメータまたはあるべき:今、私はベースソケットハンドラハンドラ(クラスの一部)を持っている.. JSONリクエストの処理および登録されているハンドラを担当するクラス - 私はGameSessionServerを持っていますジェネリックRequestDto ??????私はここのような特定のタイプにRequestDtoのキャストん具体的なハンドラで :
protected override WebSocketResponse HandleRequestInternal(RequestDto request, GameSessionServer server)
{
CasinoSpinRequestDto spinRequest = request as CasinoSpinRequestDto;
int TotalBetInCents = (spinRequest.SpinType != "free") ? spinRequest.TotalBet : 0;
JsonResult JR = null;
CasinoSpinResponseDto spinResponse = new CasinoSpinResponseDto();
switch (spinRequest.SpinType)
{
case "regular":
JR = PlayBetSpin(spinRequest, server);
break;
case "free":
JR = PlayFreeSpin(spinRequest, server.SessionContext);
break;
}
// set balance in cents
spinResponse.Credit = JR.BalanceInCents;
SlotEngineRNG engineRNG;
sbyte[,] wheels = (JR is SpinJsonResult) ? ((SpinJsonResult) JR).Wheels : ((BonusJsonResult) JR).FreeSpin.Wheels;
int rsId = (JR is SpinJsonResult) ? 0 : ((BonusJsonResult) JR).FreeSpin.ReelId;
if (SlotIsEngineRNG(server.SessionContext.SystemGameId, out engineRNG))
{
GameSettingInfo gsi = DataBuffer.Instance.GetGameSetting(server.SessionContext.UserGroupId, (int) server.SessionContext.SystemGameId);
spinResponse.Results = CalculateWheelPositionsRNG(wheels , rsId , engineRNG, gsi);
} else
{
int[] pos;
PosHoldersFactory.GetSlotPositions(server.SessionContext.SystemGameId, wheels, rsId, out pos);
spinResponse.Results = pos;
}
.......................... ......
基本クラスは、プロシージャやプロセスを繰り返さない場合に適しています。したがって、重複があり、特定のRequestDに**依存していない場合は、それをgenericにしてください。あなたはアクセスする必要があるRequestDtoの特定のプロパティを使用するためジェネリックが必要かどうかを普通は知ることができます(例えば 'Id'フィールドの場合はそれをインターフェイスに置き、汎用引数を制約できます) –
あなたのユースケースにもよりますが、コメントするのに十分なコンテキストがないと思います。おそらくあなたの現在のコードがコンパイルされ、動作するならば、クラスのジェネリックバージョンにあるメソッドやプロパティは必要ありません。 –
あなた自身のWebサーバーを書いているようですが、私はMSにはHttpServerが組み込まれていると思います... –