C
C#14mo ago
SWEETPONY

❔ How to rewrite this to linq without multiple select?

private async Task OnChannelsRegister(
IDeliveryHandlerContext context,
ChannelsRegisterArguments arguments )
{
var registerDtos = new List<ServiceRegisterDto>();
var mutationDtos = new List<ServiceMutationDto>();
var startDtos = new List<ServiceStartDto>();

foreach (var channel in arguments.Items)
{
var registerDto = new ServiceRegisterDto
{
PackageName = channel.Type.Name,
Title = channel.Type.Name,
Description = channel.Type.Description
};

registerDtos.Add(registerDto);

var mutationDto = new ServiceMutationDto
{
Name = channel.Type.Name,
Title = channel.Type.Title,
Description = channel.Type.Description,
Configuration = channel.Configuration
};

mutationDtos.Add( mutationDto );

var startDto = new ServiceStartDto
{
Name = channel.Type.Name
};

startDtos.Add( startDto );
}

await _scmClient.ServicesRegister(new ServicesRegisterArguments( registerDtos));

await _scmClient.ServicesModify(new ServicesModifyArguments( mutationDtos));

await _scmClient.ServicesStart(new ServicesStartArguments( startDtos));
}
private async Task OnChannelsRegister(
IDeliveryHandlerContext context,
ChannelsRegisterArguments arguments )
{
var registerDtos = new List<ServiceRegisterDto>();
var mutationDtos = new List<ServiceMutationDto>();
var startDtos = new List<ServiceStartDto>();

foreach (var channel in arguments.Items)
{
var registerDto = new ServiceRegisterDto
{
PackageName = channel.Type.Name,
Title = channel.Type.Name,
Description = channel.Type.Description
};

registerDtos.Add(registerDto);

var mutationDto = new ServiceMutationDto
{
Name = channel.Type.Name,
Title = channel.Type.Title,
Description = channel.Type.Description,
Configuration = channel.Configuration
};

mutationDtos.Add( mutationDto );

var startDto = new ServiceStartDto
{
Name = channel.Type.Name
};

startDtos.Add( startDto );
}

await _scmClient.ServicesRegister(new ServicesRegisterArguments( registerDtos));

await _scmClient.ServicesModify(new ServicesModifyArguments( mutationDtos));

await _scmClient.ServicesStart(new ServicesStartArguments( startDtos));
}
6 Replies
Omnissiah
Omnissiah14mo ago
i don't really see linq being used here do you mean the 3 lists?
Pobiega
Pobiega14mo ago
select is specifically an A -> B transformation. If we say that channel is your A, and the B is a tuple of (ServiceRegisterDto, ServiceMutationDto, ServiceStartDto) it would do that part for you, but you'd have one list with all the items in it, since thats what select does a single list goes in, a single list comes out
SWEETPONY
SWEETPONYOP14mo ago
hm, okay, thanks!
Denis
Denis14mo ago
$close
MODiX
MODiX14mo ago
Use the /close command to mark a forum thread as answered
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server