I have a c# struct where I need to forbid calling the no args constructor on it.
MyStruct a;
/// init a by members // OK
MyStruct b = MyStruct.Fact(args); // OK, inits by memebers
MyStruct s = new MyStruct(); // can't have that
I'm doing this mostly to force explicet values for all members as there are no valid default values and all members must have valid values.
In C++ this would be easy, add a private constructor but c# doesn't allow that.
Is there a way to prevent the above?
I really need to enforce using a factory so preventing all public constructor calls would work just as well.
Full discloser: to avoid a mono dependency, the c# app is being automatically translated to D where new Struct()
results in a pointer and this is mucking things up for me. However this question is relevant despite that so just ignore it.