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