问题: SwapDealIndexFixer(internal)访问 SwapDealService.TryGetFloatRate (protected) 报 CS0122, 因非嵌套类无权访问 protected 成员。 修复: SwapDealIndexFixer 改为接受 Func<DateTime,string,(bool,double)> 委托, SwapDealService.IndexFixer 属性传入 TryGetFloatRate 的包装。 - 无需访问 protected 成员 - SwapDealIndexFixer 保持独立文件(clean code) - virtual 接缝仍保留(测试 override TryGetFloatRate 仍生效) 验证: YLErpDAL.csproj 编译 0 错误, 全量480测试7失败(基线一致,零回归), CI_007/CI_008 通过。
29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
using System;
|
||
using YLErp.Derivatives.Interest;
|
||
|
||
namespace YLErp.Modules.SwapModule;
|
||
|
||
/// <summary>
|
||
/// 把一个取价委托包装成 IIndexFixer。
|
||
///
|
||
/// 为什么不直接用 Fr007IndexFixer.Instance:SwapDealService.TryGetFloatRate 是
|
||
/// protected virtual,测试 override 它注入 stub。静态 Instance 直接调
|
||
/// EodPriceQueryService 会绕过这个接缝,导致测试失败。
|
||
/// 本类接受取价委托(SwapDealService 传入 this.TryGetFloatRate 的包装),
|
||
/// 既保留 virtual 接缝,又用上 IndexFixerBase,且无需访问 protected 成员。
|
||
/// </summary>
|
||
internal sealed class SwapDealIndexFixer : IndexFixerBase, IIndexFixer
|
||
{
|
||
private readonly Func<DateTime, string, (bool ok, double rate)> _tryGet;
|
||
|
||
internal SwapDealIndexFixer(Func<DateTime, string, (bool ok, double rate)> tryGet)
|
||
=> _tryGet = tryGet;
|
||
|
||
public bool TryGetFixing(DateTime fixingDate, string underlyingCode, out decimal rate)
|
||
{
|
||
var (ok, r) = _tryGet(fixingDate, underlyingCode);
|
||
rate = Convert.ToDecimal(r);
|
||
return ok;
|
||
}
|
||
}
|