C
C#

help

❔ rename tuple

VVinicius12/13/2022
public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
public async Task<(List<SalesReportEntity>, int totalSales)> GetAllSalesReportAsync(int companyId, int? SalesPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate)
{
return (sales, sales.Count());
}
obs: I cut off some lines
is returning item1: [{…}] item2: 1 How can I rename it to sales and totalSales
AAngius12/13/2022
I'd probably just use a record here instead of a tuple But return (sales: sales, totalSales: sales.Count()) should work With the return type being Task<(List<SalesReportEntity> sales, int totalSales)>
Ssibber12/13/2022
this not necessary actually, if you specify the names in the return type
VVinicius12/13/2022
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
public async Task<(List<SalesReportEntity>allSales, int totalSales)> GetAllSalesReportAsync(){
return (allSales: sales, totalSales: sales.Count());
}
wont change :-:
VVinicius12/13/2022
MMODiX12/13/2022
Cyberrex#8052
REPL Result: Success
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
System.Text.Json.JsonSerializer.Serialize((allSales: 1, totalSales: 2), new JsonSerializerOptions { IncludeFields = true })
Result: string
{"Item1":1,"Item2":2}
{"Item1":1,"Item2":2}
Compile: 444.748ms | Execution: 52.984ms | React with ❌ to remove this embed.
Ssibber12/13/2022
huh
AAngius12/13/2022
I guess STJ doesn't serialize named tuples Thankfully, solution is simple: just use a record
VVinicius12/13/2022
you right
VVinicius12/13/2022
VVinicius12/13/2022
return new SalesResume(sales, sales.Count());
VVinicius12/13/2022
idk if I did best way
AAngius12/13/2022
I'd just keep the record next to the method tbh, no need to make a whole separate file for it But, sure, it works either way
VVinicius12/13/2022
Interface need to be typed as well
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
namespace Epilefinho.Domain.Repositories
{
public interface ISaleRepository
{

Task<SalesResume> GetAllSalesReportAsync(int idCompany, int? NumberPage, int? Limitpage, DateTime? StartDate, DateTime? EndDate);

}
}
I'd prefer but I couldnt
AAngius12/13/2022
Yeah, understandable
VVinicius12/13/2022
thanks
AAccord12/14/2022
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.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Search generic list for a searchwordHeeelp! deadline soon and i'm stuck.. I have a list like this: List<string[]> blogPostList = new()Remove or overwrite single element of list of arrays(not completely sure its called list of arrays) Basically i have one of these: List<string[]> blog✅ When calling a generic function, how can I tell it that I'm going to be passing null?I've got a generic function which is something like this: ```cs public ReturnType GetValue<ReturnTyp❔ WPF Textbox decimal onlyHello, i'd like to know how we are supposed to configure our textbox in order to accept only decimalmaui deserialize problemI am having a problem when trying to deserialize api data ```C# string content = await response.C❔ Log from helper class without creating new context? (Serilog)I have a bunch of services with their own dedicated loggers that have config'd settings for filterin❔ Swagger Open API not showing Request examples in the UII've written an Azure Function with Open API in C#, but when I open up the Swagger/UI to test my Azu❔ I'm building an MVC core webshop. How should I be structuring controllers, actions and views?So, right now, I have one single view, and this view renders both information about the product and ❔ How to make an object follows my mouse?so I am new at programming and trying to make a top down shooting games in windows form app. My lect❔ Is this the right way to implement an Interface```csharp interface IObstacles { void Draw(Graphics g); } class Redbox : IO❔ Is there any tool converting csv file to Class (seeding data)?I am using EF to seed data and I have an excel file containing like 500 records. If that's around 1❔ Is it possible to have WPF window hidden until Blazor WebView loads page?I'm trying to hide a WPF window until the Blazor WebView loads, but it seems that the initialization❔ SQLite in-memory Database read from ReadOnlyMemory bytesI'm receiving an SQLite database payload from an AMQP-0-9-1 message in the form of `ReadOnlyMemory<bSettings.Default not savingI have two integers, primary and secondary, that i want to persist, but they refuse to❔ need help opening siteshow do i make visual studio open a site and then press on a bar to type something❔ Generally, how do you implement a readonly struct?Hi. Generally, how do you implement a readonly struct? I mean define readonly fields or getter? What❔ How can I query a JSON doc for only objects with a specific property value?I have a JSON object that looks like this: ```json { "pagedata": [ { "id": "❔ Are TryAsync methods acceptable?I've just been refactoring some implementations of a method I have to go from `T Load()` to `bool Tr❔ Wpf chess board problemHello! Im trying to color a chess board. I have a bunch of border tags for the squares. I think it c❔ Errors when everything looks ok.So, I'm dumb a aspnet api, with controllers, using sqlite. There are no syntax errors in the code, s