【问题标题】:How to provide a user defined delegate with out parameters in Microsoft Moles如何在 Microsoft Moles 中提供带有 out 参数的用户定义委托
【发布时间】:2012-01-18 08:40:09
【问题描述】:

我想绕过一个内部方法调用,因此模拟了它。模拟的方法委托看起来像:

public Microsoft.Moles.Framework.MolesDelegates.OutOutFunc<string,string,string,
byte[]> GetlineStringStringOutStringOut { set; }

现在,在我的测试中,当我尝试访问这个模拟方法时:

GetlineStringStringOutStringOut = (a,b,c) => {return bytearray};

出现一个错误,说参数 2 和 3 必须用 out 关键字声明,但是当我用 out 关键字声明它们时,它根本无法编译。我阅读了其他 SO 问题和答案,似乎无法完成。

是否可以为此提供用户定义的委托?如果有,请举个例子。

编辑:

我试图声明我自己的委托与模拟委托具有相同的签名

static delegate byte[] MyFunc<String, String, String>
(string a, out string b, out string c);

但我不确定在调用模拟委托方法时如何调用它?

【问题讨论】:

    标签: c# unit-testing moles


    【解决方案1】:

    您需要在从 lambda 返回之前为 bc 变量赋值,并明确指定参数类型,如下所示:

    GetlineStringStringOutStringOut = (string a, out string b, out string c) => 
    { 
        b = c = string.Empty;
    
        return new byte[] { };
    };
    

    【讨论】:

      猜你喜欢
      • 2016-08-07
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多