Normally you cannot usr an ObjectId as an optional argument in C# due to the fact that ObjectId is a struct with no “Design time constant” default value.
ObjectId.Empty is a property that executes code and default(ObjectId) is not allowed for the same reason.
Does anyone have a solution on how to create a working design time constant so that the following statement would work? (This is not the real method but an example)
MyObject LoadOrCreate(ObjectId id = somedefaultvalue)
{}
If I try this with any ov the above examples it will not compile?
I can of cause use a separate overload of the method but I rather use optionals than overload.
As I noted in my comment to the first answer, nullable is an option but one I prefer to not use due to having to cast back to not nullable.
So I am still looking for some “better” solution 😉
Make it Nullable and default to null?