I wanted to know what are the possibilities (but which is the most appropriate) to do an interface cast.
public class ClasseTeste1 : IMinhaInterface { ... }
public class ClasseTeste2 : IMinhaInterface { ... }
See in the example that I'm using it in the parameter passing method.
public void MeuMetodo(IMinhaInterface parametro)
{
var objetodaClasse1 = (ClasseTeste1)parametro;
var objetodaClasse2 = (ClasseTeste2)parametro;
//Mas qual classe seria a que veio pelo parâmetro?
...
}
In this case, instead of putting the class type, I would like to get the type by the object. via some type of gettype for example.
See how I imagine it would be
public void MeuMetodo(IMinhaInterface parametro)
{
var objetodaClasse = (parametro.gettype())parametro;
...
}
However, I want to leave the class definition according to the parameter. So I would need to have some GetType to know what class to instantiate.
What else do I notice in this scenario?