Page 1 of 1

Allow private parameterless constructors to be called

Posted: Thu Sep 15, 2022 9:30 am
by Joel
Status

Requested

Complexity

7/10

Description

Allow private parameterless constructors to be called instead of just public parameterless constructors.

Note that private constructors have special meaning in CSharp and they are not necessarily designed for this purpose.

This would also require a custom implementation of Activator.CreateInstance for .NET Core platforms (e.g. Universal Windows) as this does not allow private constructors to be called. Instead the constructor would need to be invoked via reflection, and all error handling associated with that would also need to be coded.

Useful anecdote from Falondrian via Unity thread:
Also look for private parameterless constructors. Private constructors is a common pattern for serializer support, so in "normal" code the constructor doesnt get exposed. Right now I have to create ES3 types for these classes which is a bit tedious.
Note that it may be simpler to implement GetUninitializedObject so that there isn't a requirement for parameterless constructors.