I'm translating an API from C to C#, and one of the functions allocates a number of related objects, some of which are optional. The C version accepts several pointer parameters which are used to return integer handles to the objects, and the caller can pass NULL
for some of the pointers to avoid allocating those objects:
void initialize(int *mainObjPtr, int *subObjPtr, int *anotherSubObjPtr);
initialize(&mainObj, &subObj, NULL);
For the C# version, the obvious translation would use out
parameters instead of pointers:
public static void Initialize(out int mainObj, out int subObj,
out int anotherSubObj);
... but this leaves no way to indicate which objects are unwanted. Are there any well-known examples of C# APIs doing something similar that I could imitate? If not, any suggestions?