I have a C # structure where I need to prevent the constructor from calling no args 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 do this mainly to force alignment of values ββfor all members, since 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 # does not allow this.
Is there any way to prevent this?
I really need to force the factory, so preventing all constructor calls will work as well.
Full description: to avoid mono-dependency, the C # application automatically translates to D, where new Struct() leads to a pointer, and this makes me think. However, this question matters despite this, so just ignore it.
c # struct factory
BCS
source share