![](/img/trans.png)
[英]ASP.NET Core 7 valditate IAsyncEnumerable against data annotation
如何在 ASP.NET Core 7 API controller POST 操作中對作為 IAsyncEnumerable 的輸入執行數據注釋驗證。 我嘗試使用以下代碼,但未進行驗證。public record struct Car([Required][RegularExpression(@" ...
[英]ASP.NET Core 7 valditate IAsyncEnumerable against data annotation
如何在 ASP.NET Core 7 API controller POST 操作中對作為 IAsyncEnumerable 的輸入執行數據注釋驗證。 我嘗試使用以下代碼,但未進行驗證。public record struct Car([Required][RegularExpression(@" ...
[英]Tasks not running concurrently by custom LINQ operator
我正在嘗試創建SelectAwait (和其他)的並發版本,作為IAsyncEnumerable的一部分存在,它為System.Linq.Async提供擴展方法。 這是我正在使用的代碼:private async IAsyncEnumerable<TOut> SelectParallel ...
[英]How to handle errors in method that has IAsyncEnumerable as return type
我有一個 API 端點: 我希望能夠在 ArgumentException 的情況下返回類似“錯誤請求”的響應。 如果我嘗試使用 try-catch 塊,我會收到錯誤消息: CS1626:無法在帶有 catch 子句的 try 塊主體中產生值請注意,它是一個 API 端點方法,因此理想情況下錯誤處 ...
[英]Asp.Net Core API Controller method returning IAsyncEnumerable<T> not producing the intended behavior
我有一個 API 控制器設置,它返回 277,000 多個項目: 而不是流回每個位置,Asp.Net 實際上是在緩沖響應。 客戶端代碼: 從這個方法返回后我得到這個異常: 我不能使用分頁,因為我使用的是遺留數據庫,所以我試圖從 API 端點流式傳輸所有數據。 “結果”的類型是 List<Lo ...
[英]How to unit test method with IAsyncEnumerable<dynamic> return type
我有一個方法: 如何使用 Nunit 為該方法編寫單元測試? 這是我目前的做法: 我試過使用Assert.Throws和Assert.ThrowsAsync ,但沒有返回結果。 ...
[英]Calling IAsyncEnumerable<string> before other methods
大家好,我正在嘗試根據我正在使用的庫使用IAsyncEnumerable讀取文件夾中的所有文件路徑。 我已經能夠為此創建一個方法,但我面臨的挑戰是,庫方法 在調用IAsyncEnumerable之前首先被調用。 因此,值始終為 null。 我該怎么做才能確保我的參數不是 null。請檢查下面的代碼: ...
[英]Return IAsyncEnumerable from grpc with timeout try-catch
我有一個 gRPC 客戶端,我想有一個方法來簡化它的使用。 該方法應返回從IAsyncEnumerable服務器流式傳輸的項目的 IAsyncEnumerable。 我有一個指定的流式傳輸超時不超過。 如果發生超時,我只想帶走到目前為止我設法獲取的所有項目。 這是我嘗試做的: public ...
[英]Buffering IAsyncEnumerable in producer/consumer scenario
我有一個場景,我正在從數據庫中讀取一些數據。 此數據以IAsyncEnumerable<MyData>的形式返回。 讀取數據后,我想將其發送給消費者。 這個消費者是異步的。 現在我的代碼看起來像這樣:// C# IAsyncEnumerable<MyData> enumer ...
[英]Calling IAsyncEnumerable inside constructor
我有下面的代碼,這導致我死鎖。 在代碼中,我需要調用數據庫來填充構造函數中的列表。 數據庫調用返回一個 IAsyncEnumerable。 關於如何在不導致死鎖的情況下執行此操作的任何線索? 謝謝, 格雷森 ...
[英]Conform IAsyncEnumerable to Dataflow ISourceBlock
我有一個現有的轉換 function Func<IAsyncEnumerable<TIn>, IAsyncEnumerable<TOut>>我想在數據流管道中使用。 In order to link this transformation function, ...
[英]From IEnumerable<Task<T>> to IAsyncEnumerable<T> by yield returning inside a Parallel.ForEach/Parallel.ForEachAsync gives error CS1621
在 .NET 6 項目中,我必須調用 web API,它是偏移分頁(頁面/每頁),我想讓 n 調用盡可能並行。 這是使用給定頁碼一次調用 API 的方法: What I actually need is a forward only streamable iterator of all the ...
[英]await IAsyncEnumerable<T> where is it used?
它在這里說: 從 C# 8.0 開始, IAsyncEnumerable<T> ,用於返回異步 stream的異步方法。 問題。 除了指定的foreach示例之外,是否可以通過IAsyncEnumerable<T>以某種方式使用更多的await ,或者它是專門為foreac ...
[英]How to iterate dictionary in "await foreach"
幫忙解決一個小問題... 我有一個返回字典的方法。 我需要以這樣一種方式重寫它,以便我可以使用await foreach枚舉此方法的結果。 請幫助我,有些東西根本不適合我。 這是我的方法: 要在await foreach循環中使用字典,此方法需要返回值IAsyncEnumerable<KeyV ...
[英]Checking throws exception in IAsyncEnumerable method - xUnit
我有一個這樣的異步方法: 現在我想測試這個方法拋出異常。 如何使用xUnit或FluentAssertion and xUnit做到這一點? ...
[英]How GroupBy works with IAsyncEnumerable?
我已經在有分頁的HttpClient請求中實現IAsyncEnumerable ,但我還需要對它們進行GroupBy 。 所以我實現了如下代碼; 正如我所料,這段代碼工作得很好。 但我想了解GroupBy是如何在這里工作的,因為它應該有所有按 id 分組的項目有什么我想念的嗎? 或者有什么我可以重 ...
[英]Use IAsyncEnumerable to replace Task and Action delegate
我應該實現一個可以返回設備列表的方法。 目標是在找到設備后立即返回設備,而無需等待搜索完成。 為此,我想我使用IAsyncEnumerable 。 我實現的 Discover 方法有一個Action ,一旦找到一個項目,它就會負責將項目添加到列表中。 如何修改Action並確保新設備未添加到列表中, ...
[英]ASP.NET Core stream an IAsyncEnumerate on nested property
我已閱讀有關返回IAsyncEnumerate<Entity>以利用 HTTP 流的信息。 如果我將IAsyncEnumerate<Entity>作為頂級返回,這將起作用。 所以,在客戶端:Stream responseStream = await response.Con ...
[英]Writing and reading to/from gRPC full duplex channel in .NET simultaneously using async enumerables
我有一個客戶端-服務器場景,其中管道完全使用 gRPC 雙工流實現。 管道由客戶端啟動。 在每一步(雙工調用),客戶端從 IAsyncEnumerable 讀取項目並將它們寫入通道。 這些項目由服務器處理,其中一些在通道上異步發送回。 然后客戶端返回帶有產量的讀取項目。 我有 4 種方法像這樣被鏈接 ...
[英]Parallel receiving data from several IAsyncEnumerable streams
我有一個案例需要從多個 IAsyncEnumerable 源接收數據。 為了提高性能,它應該以並行方式執行。 我已經使用AsyncAwaitBestPractices 、System.Threading.Tasks.Dataflow和System.Linq.Async nuget 包編寫了這樣的代碼 ...
[英]Deserializing to AsyncEnumerable using Newtonsoft.Json
System.Text.Json.JsonSerializer.DeserializeAsyncEnumerable<T>是 System.Text.Json 的一種方法,它可以采用Stream並生成IAsyncEnumerable<T> ,其中枚舉可以是異步的。 例如,這 ...