3
I have a question here.
I have an object (Object) received by parameter. It can be a single object or a list of objects (List).
Can I convert the object to a List object WITHOUT RECEIVING THE TYPE by parameter? I don’t want the method signed with .
An important limitation: I am using Framework 2.0. So, no Linux and other scripts that could help my life to be happier... rs...
-- adding more information, here is the question itself:
public class Conversor
{
private class MinhaClasse
{
private string _meuNome;
public string MeuNome
{
get { return _meuNome; }
set { _meuNome = value; }
}
private int _minhaIdade;
public int MinhaIdade
{
get { return _minhaIdade; }
set { _minhaIdade = value; }
}
}
public Conversor()
{
object lista = new List<MinhaClasse>();
// E agora, como eu faço para transformar o objeto 'lista' em List<MinhaClasse> em tempo de execução para usar em um loop, por exemplo?
// Lembrando que eu não quero assinar o método com o tipo genérico usando <T>, porque posso ter
// que chamar o método de forma recursivo.
}
}
Thank you.
Put your code in, give us a better context to understand what you need and give us a more suitable solution. We need to understand what information you have available, what should happen if it is not possible, if there are guarantees if it will always be possible, etc. I think you have better solution than you think.
– Maniero
Thanks for the @bigown reply. I added details as you soliciou.
– Rubens
What was missing is exactly how it will be used. The way it is just take that
object
and declare the list and it’s all right. I know this isn’t what you want, but the question doesn’t make it clear what you want.– Maniero
From what I understand, you want the Converter not to have the responsibility to say the type, but to call the method, right?
– Gabriel Katakura
At the end of the accounts, the converter will return me a string with the objects in JSON format... But as I do not have this feature native in . NET 2.0, I’m writing something a little more specific for the project I’m working on. This project is going to die soon, but I need it working.
– Rubens