This article explores the challenges of implementing type inference in C#, focusing on the limitations and potential solutions for partial generic type inference.
The use描述的情況是特定基類應使用的擴展方法,其中具有與方法參數相關的通用參數。但是,擴展方法還應返回與所調用的特定後代相關的特定類型。
溶液This approach requires specifying both generic type arguments during invocation, which may not be desirable in all cases.
Method 2: Using Two Functions with WrapperThis approach involves splitting the operation into two functions:
public static thatwrapper
public static TReg Parameter通過將擴展方法直接引入基類,可以避免問題。但是,這種方法刪除了將來在其他類上使用擴展方法的能力。(this TReg p, string name, T value) where TReg : ParameterizedRegistrationBase
部分通用類型的推廣在C#中不直接支持,但是有一些可提供類似功能的解決方法。使用的特定方法取決於所涉及的特定要求和權衡。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3