In fase di esecuzione ottengo l'istanza in box di qualche tipo. Come cancellarlo in un tipo sottostante?Come annullare l'estrazione dall'oggetto per scriverlo, non conoscendo quel tipo al momento della compilazione?
Object obj;
String variable = "Some text";
obj = variable // boxing;
// explicit unboxing, because we know the type of variable at compile time.
var x = (String)obj
// Now let's pretend that we don't know the type of underlying object at compile time.
Type desiredType = obj.GetType(); // But we can figure out.
//And now the question.
//How to express something like this:
var y = (desiredType)obj; //Need to get unboxed instance of initial variable here;
'STRING' è un tipo di riferimento, quindi nessun boxe verificano durante la conversione in' object' –
oggetti di tipo _value hanno due rappresentazioni: un modulo unboxed e una forma scatolata. I tipi di riferimento (come 'stringa') sono sempre in una forma scatolata ._ –
Forse un cattivo esempio con la stringa. Ma mai meno come farlo? –