当前位置: 首页>>代码示例>>C#>>正文


C# TextReader.ReadJsonAsync方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:kfazi,项目名称:AgarIo,代码行数:28,代码来源:AdminCommandFactory.cs

示例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();
            }
        }
开发者ID:kfazi,项目名称:AgarIo,代码行数:26,代码来源:PlayerCommandFactory.cs


注:本文中的System.IO.TextReader.ReadJsonAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。