Structs defined in C# can't have parameterless constructors. However, as I understand, such constructors are allowed by CLR. There are .NET libraries that contain them (see structs like Vector3 in UnityEngine.CoreModule which is .NET 3.5).
The question is, is there an easy way to add parameterless constructors to some structs in my .NET assembly (not in its source code)? Should I somehow mess with the assembly's IL after building it? How possibly Unity could have achieved this with their assembly?
UPDATE: actually all structs have an implicit parameterless constructor created by compiler, even if there is a parameterful constructor defined (see AndyJ's comments below). There is nothing magical in Unity3D's structs. Still I'm curious about a way to add a custom parameterless constructor to a class.
I know the behaviour of such constructors can cause confusion (see linked question), but I'm anyway curious how to have one. If someone is interested why: this all started with my DI container (Zenject) that is in some cases trying to create instances of my structs using parameterful constructors. It fails because it doesn't know how to resolve primitive types (like Int32) in my struct's constructor. I can easily avoid this by creating a binding from Int32 to 0 — however, before realising this, my curiosity has already awaken.
Vector3
has a parameterless constructor? I can't see it in the documentation of various forms of source code I looked at. Obviously it has the "normal" one which constructors it to 0, but you say it has a custom one? – user310988