I know that you can directly invoke the static constructor of a type and I know that you can create an instance of an object without calling the constructor, but is there a way to run the constructor of a type (.ctor
) on an already existing instance?
I'm looking for something like:
public static void Reinitialize<T>(T instance)
{
var initializer = typeof(T).GetHiddenConstructorThatDoesntNew(typeof(int), typeof(string));
// call the constructor (int, string) on instance
initializer.Invoke(instance, 7, "Bill");
}
I am aware that I should never really need to do this, I am more wondering if it is possible to re-invoke the constructor/initializer on an already created object.