Skip to content

Instantly share code, notes, and snippets.

@forki
Created March 21, 2011 09:33
Show Gist options
  • Save forki/879219 to your computer and use it in GitHub Desktop.
Save forki/879219 to your computer and use it in GitHub Desktop.
Mechanical transformation from out parameters to tuples.
public class SdkClass
{
public int GetInfo(string param1, out string outParam)
{
// ...
var errorCode = 1;
outParam = "MyInfo";
return errorCode;
}
}
// This transformation is very mechanical, but allows to access both function results in a pipelined manner.
// I think I would not write tests for this class, but I would consider to codegen this code if you use it a lot.
public class TupledSdkClass
{
readonly SdkClass _sdk;
public TupledSdkClass(SdkClass sdk)
{
_sdk = sdk;
}
public Tuple<int, string> GetInfo(string param1)
{
string outParam;
var result = _sdk.GetInfo(param1, out outParam);
return Tuple.Create(result, outParam);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment