My question is relatively simple, i've the sensation that the method GetUninitializedObject( type) do not generate a new instance of a given type without call any constructor but generate a new Object that act like the correct ones (has the same structure) and apparently has the same type (but internally remain an Object).
I say that because recently i've try to clone a Form.Button using GetUninitializedObject to generate the new instances of the types i need during that operation (i operate recursively on the source object), my result has the correct structure (and immediate windows also say it has the correct type ) but if i try to do MyForm.Components.Add ( clonedButton) i receive an exception with message : "Unable to cast object of type 'System.Object' to type 'ControlCollection'" (but i've checked the clonedButton type is Button and its inheritances are correct too, manually i've check almost all the structures ,inside the cloned button, and match to the source Button object and i've accessed both pubblic and private fields).
So this is the why of my question (because i had a similar issue in javascript when, in the same clonation context i generate object form base Object and then add field with the right name and structure, the compiler discover my trick watching what is the called constructor of each instance, so i've supposed it could be a similar situation), if anyone can explain me the magics behind the GetUninitializedObject() it should help much ( thanks in advance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With