You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

I3CHostInterface.cs的GetDeviceList返回值无法传递到AnalyzerViewModel.cs问题求助

I3CHostInterface到AnalyzerViewModel传值问题解决方案

核心故障原因排查

  • 方法调用路径错误:GetDeviceList是定义在I3CHostInterface类下的静态方法,你当前代码中直接调用HostInterface.GetDeviceList属于类名引用错误,无法正确触发目标方法
  • 静态实例未初始化:仅声明了public static HostInterface _instance;未做赋值操作,如果DeviceConfiguration.GetNodeList依赖该实例的初始化状态,会导致返回结果为空
  • 命名空间缺失:AnalyzerViewModel.cs未引用I3CHostInterface所在的命名空间,导致类和方法无法被正确识别
  • 底层方法返回空:DeviceConfiguration.GetNodeList内部逻辑异常,没有返回符合要求的节点数组

修正代码

I3CHostInterface.cs 调整后代码

public class I3CHostInterface
{
    // 初始化静态实例,避免依赖实例的逻辑异常
    public static HostInterface _instance = new HostInterface();
    
    public static NodeStructure[] GetDeviceList(eNodeType nodeType)
    {
        // 新增空返回兼容,避免上层调用报错
        return DeviceConfiguration.GetNodeList(nodeType) ?? Array.Empty<NodeStructure>();
    }
}

AnalyzerViewModel.cs 调整后代码

// 顶部先引入I3CHostInterface所在的命名空间,示例:
// using YourProjectName.InterfaceFolder;

var traceDevice = new TraceConfigurations();
traceDevice.NodeList = new List<NodeStructure>();
// 修正类名,用I3CHostInterface调用静态方法
var masterDeviceList = I3CHostInterface.GetDeviceList(eNodeType.Master);
// 新增非空判断,避免AddRange传入空值报错
if (masterDeviceList.Length > 0)
{
    traceDevice.NodeList.AddRange(masterDeviceList);
}

调试验证步骤

  • 给I3CHostInterface.GetDeviceList方法打断点,确认方法被正常触发,返回的数组长度符合预期
  • 给ViewModel中masterDeviceList赋值行打断点,确认返回值正常传递到ViewModel层
  • 若返回值为空,排查DeviceConfiguration.GetNodeList内部逻辑,确认节点配置数据是否正常加载

内容的提问来源于stack exchange,提问作者falcon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 10:36:03