Questo ha dimostrato di essere un po 'complicato per me finora. Mi chiedo se è possibile digitare cast un oggetto usando un oggetto System.Type.Inserisci un oggetto utilizzando un oggetto "Tipo" in C#
ho illustrato qui di seguito quello che voglio dire:
public interface IDataAdapter
{
object Transform(object input);
Type GetOutputType();
}
public class SomeRandomAdapter : IDataAdapter
{
public object Transform(object input)
{
string output;
// Do some stuff to transform input to output...
return output;
}
public Type GetOutputType()
{
return typeof(string);
}
}
// Later when using the above methods I would like to be able to go...
var output = t.Transform(input) as t.GetOutputType();
Quanto sopra è un'interfaccia generica ed è per questo che sto usando "oggetto" per i tipi.
I non è riuscito a chiarire nell'esempio, ma i due metodi si trovano all'interno di un'interfaccia IDataAdapter. – Ryall
Grazie ancora Jeff. – Ryall
Nessun problema, e ho aggiornato di nuovo la mia risposta. –