How to provide a user defined delegate with out parameters in Microsoft Moles
Asked Answered
C

1

5

I wanted to bypass an internal method call and hence have mocked it. The mocked method delegate looks like:

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

Now, in my test when I try to access this mocked method like:

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

an error occurs saying parameter 2 and 3 must be declared with out keyword but when I declare them with out keyword it's doesn't compile at all. I read other SO questions and answers and it seems it can't be done.

Is it possible to provide user defined delegate for this? If yes, please give an example.

EDIT:

I tried to declare my own delegate of same signature as mocked delegate

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

but I'm not sure how can I call this while calling the mocked delegate method?

Coetaneous answered 12/12, 2011 at 10:27 Comment(0)
C
7

You need to assign values to b and c variables before returning from your lambda and also specify the parameters types explicitly, something like this:

GetlineStringStringOutStringOut = (string a, out string b, out string c) => 
{ 
    b = c = string.Empty;

    return new byte[] { };
};
Cw answered 12/12, 2011 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.