本文整理汇总了C#中System.IO.TextReader.ReadJsonAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.ReadJsonAsync方法的具体用法?C# TextReader.ReadJsonAsync怎么用?C# TextReader.ReadJsonAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.ReadJsonAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAsync
public async Task<AdminCommand> CreateAsync(TextReader reader, CancellationToken cancellationToken)
{
var json = await reader.ReadJsonAsync(cancellationToken);
if (string.IsNullOrWhiteSpace(json))
{
return null;
}
var adminCommandDto = json.FromJson<AdminCommandDto>();
switch (adminCommandDto.Type)
{
case AdminCommandType.StartGame:
var startGameAdminCommandDto = json.FromJson<StartGameAdminCommandDto>();
return new StartGameAdminCommand(startGameAdminCommandDto.Size, _physics, _stateTracker, _playerRepository);
case AdminCommandType.StopGame:
return new StopGameAdminCommand();
case AdminCommandType.GetSnapshot:
return new GetSnapshotAdminCommand();
case AdminCommandType.StartPushingState:
return new StartPushingStateAdminCommand();
case AdminCommandType.UpdateSettings:
var updateSettingsAdminCommandDto = json.FromJson<UpdateSettingsAdminCommandDto>();
var settings = Mapper.Map<WorldSettings>(updateSettingsAdminCommandDto.Settings);
return new UpdateSettingsAdminCommand(settings);
default:
throw new ArgumentOutOfRangeException();
}
}
示例2: CreateAsync
public async Task<PlayerCommand> CreateAsync(TextReader reader, CancellationToken cancellationToken)
{
var json = await reader.ReadJsonAsync(cancellationToken);
if (string.IsNullOrWhiteSpace(json))
{
return null;
}
var playerCommandDto = json.FromJson<PlayerCommandDto>();
switch (playerCommandDto.Type)
{
case PlayerCommandType.Move:
var movePlayerCommandDto = json.FromJson<MovePlayerCommandDto>();
return new MovePlayerCommand((float)movePlayerCommandDto.Dx, (float)movePlayerCommandDto.Dy);
case PlayerCommandType.Join:
return new JoinPlayerCommand();
case PlayerCommandType.GetView:
return new GetViewPlayerCommand(_physics);
case PlayerCommandType.Split:
return new SplitPlayerCommand();
case PlayerCommandType.EjectMass:
return new EjectMassPlayerCommand();
default:
throw new ArgumentOutOfRangeException();
}
}